sbjumani
sbjumani

Reputation: 124

$(document).ready Javascript fails to execute when reloading page

.

Code inside $(document).ready is not being called when another page in the site redirects to the page.

Using Spring MVC

Page 1 url: /location/. This contains the below snippet after the tag. This URL is tagged as the home URL for the site as the user enters from here.

</body>
<script>
$(document).ready(function () {

    initializeCustomerPage();
});

$(window).resize(function() { google.maps.event.trigger(confirm_map,
'resize'); map.setCenter(latlng,15); });
</script>
</html>

There are a lot of operations on this page and then it takes the user to page 2. Upon successful completion of actions in page 2, the user clicks on the home link.

Now, the page 1 loads, but the above JavaScript function does not get executed.

Please let me know if any other code snippet from my sample is needed to help guide.

Firefox console messages seen:

SyntaxError: Using //@ to indicate sourceMappingURL pragmas is deprecated. Use //# instead jquery.mobile-1.3.1.min.js:7 Error: http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.js is being assigned a //# sourceMappingURL, but already has one Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help http://xhr.spec.whatwg.org/ confirm.js:52 Empty string passed to getElementById(). jquery.mobile-1.3.1.min.js:6 Use of getPreventDefault() is deprecated. Use defaultPrevented instead. jquery-1.8.2.min.js:2 ReferenceError: rd is not defined main.js line 53 > eval:39

I am using jquery mobile so all the responses are being added to the same DOM. Due to this the original page is in the DOM and hence never being reloaded as it was never taken out. This means that the document is already there so .ready is never triggered. To solve my problem I used 'rel="external"' on the relevant or to force the DOM to be refreshed.

Upvotes: 0

Views: 2471

Answers (1)

Robert Levy
Robert Levy

Reputation: 29073

The last line of your console logs indicates the source of the problem: rd is not defined main.js line 53. Check out what's going on in that part of the code.

Upvotes: 2

Related Questions