Domanda

When I get an url that contains <script src="some-file.js"></script> as the follow example:

<html>
<script>
$(document).ready(function(){
    $.get('/some-url', function(r) {
        $('#html-container').html(r); // Contains: <script src="some-file.js"></script>
    });
});
</script>

<body>
<div id="html-container"></div>
</body>

This is result as sayed before in a autoload from some-file.js as result from /some-url than jQuery will add ?_={random number} to query string.

Resulting in the request: GET some-file.js?_=1365695139815

How can I disable this random request append from autoload from html() parse?

@edit

Since I can't make the request, it's because they are executed by html parse, with the Brian's answer I found this simple solution:

$.ajaxSetup({
    // Enable caching of AJAX responses
    cache: true
});

Found at How to set cache: false in jQuery.get call

È stato utile?

Soluzione

The jQuery appended query string is a result of jQuery's cache busting for ajax calls. To disable this, use the following:

$.ajax({
    url: '/some-url',
    cache: true,
    success: function(r) {
        $('#html-container').html(r); // Contains: <script src="some-file.js"></script>
    }
});

cache: true being the important part.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top