Reputation: 1232
I am fairly new to AJAX
I have a webpage (say webpage A) which upon a certain button press, calls webpage B through AJAX. webpage B is having 2 javascript files included. Now whenever I click the button, the javascript files are not being loaded. its correspoing CSS files are loaded successfully by AJAX. Here is what I got after inspection-
Here arise my question 1- how is it making call to wdm.js? = some random number ??
Now, for the workaround, I have tried to load the javascript files by using jQuery.getScript()
function using this code-
$.ajax({
type: "POST", url: "webpageB.php", data: "id="+id,
complete: function(data){
//some code
$.getScript('js/wdm.js');
// some code
}
});
still I am getting this error now-
Now my question 2 arises here- Why is that the random number, came out of nowhere, is appearing into ajax GET request?
I can not use the javascript on webpage A for some reasons, So the only option left is to load the javascripts dynamically (synchronously with DOM elements of webpage B). Can anyone suggest some method?
Edited- using the function ajaxsetup
do remove the random number appearing in the URL, but now I see the file is still not being loaded by ajax, even though chrome inspector(which I use to monitor the ajax calls) do not show any errors. Now the situation is bit complex.
Upvotes: 3
Views: 688
Reputation: 10224
Random number is timestamp which is used to prevent browser's cache. If that's not what you want, add cache : true
option in ajax call. For example: $.ajax({url: "url", success: callback, cache: true});
. If you want to prevent all future AJAX requests from being cached by default(this is actually the default setting in jQuery):
$(document).ready(function() {
$.ajaxSetup({ cache: true });
});
Upvotes: 1
Reputation: 82287
Why is that the random number, came out of nowhere, is appearing into ajax GET request?
This random number, applied in such a manner, is utterly useless in its content. It is used for cache busting. Basically, having that query string attached to the file reference will ensure that a cached version of the file is never used.
Upvotes: 0