本文介绍了使$ .getScript(“")不在请求末尾添加数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用$.getScript()从某个地方获取脚本.

I am using $.getScript() to get a script from somewhere.

function fetch(url){
window.setInterval(function (){
$.getScript(url);
},50000)
}

fetch("http://example.com/script.js");

但是,当我查看FireBug开发人员控制台时,我发现它添加了其他数字.这是输出:

However, when I look at the FireBug developer console, I have seen that it adds additional ?numbers. Here is the output:

<script async="" src="http://example.com/script.js?7330519448833367000&_=1416681336440">

远程服务器已禁用?从他们的htaccess字符.我需要使用$.getScript("")来获取远程脚本,但是如何防止添加其他数字的功能?

The remote server has disabled the ? char from their htaccess. I need to use $.getScript("") to get the remote script, but how is it possible to prevent the function that adding additional ?numbers ?

推荐答案

这是因为当您使用$.getScript()时,jQuery将缓存设置为false(默认情况下).

It's because jQuery sets caching to false (by default) when you use $.getScript().

来自 jQuery文档:

要禁用缓存,请在$.getScript调用之前添加以下内容:

To disable caching, add the following before the $.getScript call:

$.ajaxSetup({
    cache: true
});

这篇关于使$ .getScript(“")不在请求末尾添加数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 21:03