How to get a script file by $ .getScript ()

I am trying to import some javascript files from some code hosts.

    $.when(
        $.getScript('http://pingzi.googlecode.com/svn-history/r30/branches/wangqi/web/jquery.window.min.js'),
        $.getScript('http://mottie.github.com/tablesorter/js/jquery.tablesorter.js'),
        $.getScript('http://tconnell.com/samples/scroller/lib/jquery.tablesorter.scroller.js'),
        $.getScript('http://code.highcharts.com/stock/highstock.js'), 
        $.Deferred(
            function(deferred) { 
                $(deferred.resolve);
            }
        )
    ).done(function() {  
       // my function goes here....
    });

When I try to call these URLs to import js files, the URLs will be added ?_=1344036242417and then I would not be able to access the script file that I want.

i.e. "NetworkError: 404 Not Found - http://pingzi.googlecode.com/svn-history/r30/branches/wangqi/web/jquery.window.min.js?_=1344036242417"

Anyone have any ideas on how to get around this? Thanks in advance.

+5
source share
4 answers

This is because ajax caching is disabled by default in jQuery in order to enable it and remove querystring:

$.ajaxSetup({ 
    cache: true 
}); 

ajax, , docs getScript , , getScript, cachedScript.

$.getScript, , / , true false:

$.getScript = function(url, callback, cache){
    $.ajax({
            type: "GET",
            url: url,
            success: callback,
            dataType: "script",
            cache: cache
    });
};
+7

jQuery . , , :

$.ajaxSetup({
  cache: true
});

: http://api.jquery.com/jQuery.getScript/#caching-requests

+5

jQuery _=1344036242417, URL-. :

jQuery : Ajax . , $.ajaxSetup $.getScript() cache: true.

[sic], $.getScript() false. URL- , , script , . , , $.ajaxSetup():

$.ajaxSetup({
    cache: true
});
+4

. :

$.ajaxSetup({
  cache: true
});
+2

All Articles