Reputation: 2591
I'm trying to load some jquery javascript when my page is loaded, but it's always loaded twice. I'm using jquery 1.7.2 and jquery mobile 1.1.0. I tried this 3 different methods, but it's always loading the script twice.
$(document).bind("ready", function() { }
$(document).ready(function() { }
$(document).live('pageinit',function(event) { }
Edit: i solved it, shit ! i'm 100% sure this mistake will happen to nobody else, i'm sorry for this stupid problem.
Upvotes: 2
Views: 3650
Reputation: 101
I was having the same problem with jqueryMobile as described above. That is, all scripts placed in the body would load twice. If placed in , they would load only once as expected.
I resolved the double loading in body issue by changing the root (first div after the start of the body) to include a data-role of "page":
<body>
<div data-role="page">
Voila, no more double loading!
This has been a common problem with users of the new HTML5BoilerPlate.
Upvotes: 7
Reputation: 311
My Scripts were getting called twice in jQueryMobile 1.3.0 and I just fixed the issue by using jquery-1.9.1 instead of jquery-1.7.2.
Also you can use jQuery Migrate Plugin
i.e. < script src="http://code.jquery.com/jquery-migrate-1.1.0.min.js">< /script>
for backward compatibility with previous versions of jQuery.
Upvotes: 0
Reputation: 9244
Update: I tried this locally with jQuery 1.7.2 and jQuery Mobile 1.1.0 and it works fine. I'm seeing one 1 call to the pageinit
event. I even tried multiple pages and still see only one call to pageinit
.
You generally don't want to use the ready event with jQuery Mobile, but stick to just the pageinit
event. As per the jQuery mobile events documentation...
Triggered on the page being initialized, after initialization occurs. We recommend binding to this event instead of DOM ready() because this will work regardless of whether the page is loaded directly or if the content is pulled into another page as part of the Ajax navigation system.
For a more specific answer, you really need to post actual code; however, with your mixing of ready
and pageinit
in your question, I am guessing pageinit
and ready
are both calling the same code.
Upvotes: 2
Reputation: 34416
jQuery 1.7.2 is not fully tested with jQuery Mobile 1.1.0 at this point. You may want to use jQuery 1.7.1.
Support for jQuery 1.7.1
jQuery Mobile 1.1.0 now supports both 1.6.4 and 1.7.1 versions of jQuery core. We recommend that you use 1.7.1 to take advantage of all the great improvements in the latest release. If you stick with 1.0.1 for a while, remember that only supports 1.6.4. We’re still testign 1.7.2 and will officially support that in a future release.
Upvotes: 2