我创建了一个函数,该函数使用 jquery.ajax 来测试 URL 上是否存在文件。该函数由 IF 语句调用,该语句返回Ok it exists文件是否在那里或it doesn't exist, 到 wabpage 本身的 ID。使用 Chrome 和 IE 这可以正常工作。使用 FF,它始终返回it doesn't exist并且不会在控制台中生成错误。function UrlExists(urlCheck){ var http = jQuery.ajax({ type:"HEAD", //Not get url: urlCheck, async: false }); return http.status!=404;}var urlToCheck = "https://example.org/filetocheck.txt";if(UrlExists(urlToCheck)){ $('#exists').html("Ok it exists");} else { $('#exists').html("it doesn't exist");}考虑缓存,我发送以下标题,当页面被调用时没有解决问题header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");header("Cache-Control: post-check=0, pre-check=0", false);header("Pragma: no-cache");不用说 CTRL+F5 也不起作用。有什么我可以做的才能让它在 FF 上工作吗?
2 回答
![?](http://img1.sycdn.imooc.com/54584ee0000179f302200220-100-100.jpg)
隔江千里
TA贡献1906条经验 获得超10个赞
您可以设置cachejQuery Ajax 的属性false来防止这种情况。
function UrlExists(urlCheck){
var http = jQuery.ajax({
type:"HEAD", //Not get
url: urlCheck,
async: false,
cache: false,
});
return http.status!=404; }
添加回答
举报
0/150
提交
取消