To answer your original question, you see the timestamp appended because jQuery by default sets cache: false
for script
and jsonp
calls which appends the timestamp to the URL.
To avoid the timestamp, you can do this:
$.ajaxPrefilter(function( options, originalOptions, jqXHR ) {
if ( options.dataType == 'script' || originalOptions.dataType == 'script' ) {
options.cache = true;
}
});
This sets up a global prefilter for all $.ajax
calls, including the ones made by jQuery while requesting the script
.
We inspect the dataType
to make sure we're not inadvertantly targetting other ajax calls and explicitly set cache
to true
. This will avoid the timestamp appending problem.
You can now use your original code and it'll pick it up from cache.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…