当我得到一个包含<script src="some-file.js"></script>
如下示例的 url 时:
<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>
这是之前在自动加载中some-file.js
所说的结果,/some-url
因为 jQuery 将添加?_={random number}
到查询字符串中。
导致请求:GETsome-file.js?_=1365695139815
如何从 html() 解析的自动加载中禁用此随机请求附加?
@编辑
由于我无法发出请求,这是因为它们是由 html 解析执行的,在 Brian 的回答下,我找到了这个简单的解决方案:
$.ajaxSetup({
// Enable caching of AJAX responses
cache: true
});