Microsoft Edge缓存Ajax请求? [英] Microsoft Edge caching Ajax requests?

查看:245
本文介绍了Microsoft Edge缓存Ajax请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我有一个用于在网站上加载内容的ajax系统,它的工作方式如下:

So I have an ajax system for loading content on a website, it works like this:

单击按钮时,将调用Javascript函数:

When clicking a button, a Javascript function is called:

onclick="doSomething('abc')"

我的Javascript如下:

My Javascript looks like this:

//Ajax
var xmlhttp;
function loadXMLDoc(url,cfunc) {
    if (window.XMLHttpRequest) {
        // code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp=new XMLHttpRequest();
    } else {
        // code for IE6, IE5
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange=cfunc;
    xmlhttp.open("GET",url,true);
    xmlhttp.send();
}
function doSomething(var) {
    loadXMLDoc("http://www.website.com/ajax/doSomething.php?var="+var, function() {
        if (xmlhttp.readyState==4 && xmlhttp.status==200) {
            document.getElementById("response-container").innerHTML=xmlhttp.responseText;
        }
    });
}

一个名为echo的PHP文件有点像这样:

The PHP file called just echo's text a bit like this:

echo "Response here";

通常,每次运行此Javascript函数时,我都会使用这种类型的系统在具有特定ID的元素中加载新内容.

In general, I use this type of system to load new content in an element with a particular id each time this Javascript function is run.

这已经完美地工作了3年多了,但是出于某些原因,Microsoft Edge正在缓存对此的响应.因此,根本无法正确生成内容.因此,您只需运行一次,并且在x时间内,它只会继续返回相同的缓存响应.

This has worked perfectly for just over 3 years now, but for some reason Microsoft Edge is caching the response from this. So the content isn't being generated correctly at all. So you run this once, and for x amount of time it will just keep returning that same cached response.

有什么想法可以解决此问题吗?我曾经提到过使用标头,但是我不确定在这种情况下如何应用修复程序.

Any ideas what the correct fix for this is? I've seen mention of using headers, but I'm not sure how to apply a fix in this situation.

推荐答案

我们也遇到了Edge和IE 10/11上缓存的ajax请求的问题.我们的解决方案是使用 HTTP标头 Cache-Control: no-cache这也没有时间戳.

We had problems with cached ajax requests on Edge and IE 10/11 too. Our solution was the use of the HTTP-header Cache-Control: no-cache This works without a timestamp too.

这篇关于Microsoft Edge缓存Ajax请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆