Rag*_*azs 2 jquery html-parsing autoloader
当我收到包含<script src="some-file.js"></script>以下示例的网址时:
<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>
Run Code Online (Sandbox Code Playgroud)
如前所述,此some-file.js结果来自/some-urljQuery将自动添加?_={random number}到查询字符串中的结果。
结果请求:GET some-file.js?_=1365695139815
如何从html()解析的自动加载中禁用此随机请求追加?
@编辑
由于我无法发出请求,这是因为它们是通过html解析执行的,有了Brian的回答,我找到了一个简单的解决方案:
$.ajaxSetup({
// Enable caching of AJAX responses
cache: true
});
Run Code Online (Sandbox Code Playgroud)
jQuery附加查询字符串是jQuery对ajax调用进行缓存清除的结果。要禁用此功能,请使用以下命令:
$.ajax({
url: '/some-url',
cache: true,
success: function(r) {
$('#html-container').html(r); // Contains: <script src="some-file.js"></script>
}
});
Run Code Online (Sandbox Code Playgroud)
cache: true 是重要的部分。