The best place to ask programming/development questions, imo. UPDATE: stackoverflow is the *worst* place to *ask* questions (if your first question/comment doesn't get any up-rating/response, then u can't ask anymore questions--ridiculously unrealistic), but a great reference for finding answers.

My Music (Nickleus)

20160531

[SOLVED] php+jquery page loading twice (2 GET requests) instead of once

i was using jquery to set an element's css background-image inside $(document).ready(function()... , and when i removed that code th page would load once instead of twice:

var url = el.data("imgbg");  // get the url string
el.css("background-image", "url('"+url+"')");  // set bgimg url

what was causing the extra page reload/GET request was an empty url string!

putting a simple if-test on url fixed it:

if (url != "") el.css("background-image", "url('"+url+"')");

:)

my fiddle confirming this behavior:

No comments:

Post a Comment