简体   繁体   中英

Getting 304 error for an ajax call with using IE browser

I wrote an ajax call but I have a problem with IE web browser because in Chrome, ajaxFunction(1) is working properly (it gets 200 OK on network section of my browser while I am browsering). On the other hand same page with same actions with using IE, function returns 304 error . I tried manually ( call.php?which=1 ) with using IE, it is working. I could not find what is the problem in this case?

PS. My codes are working in manual. I want to know what is my problem with IE browser. Which codes run different in browsers?

Here is some codes:

function ajaxFunction(a)
{
    var ajaxRequest;
    try {
        ajaxRequest = new XMLHttpRequest();
    } catch (e) {
        try {
            ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {
                alert("Your browser broke!");
                return false;
            }
        }
    }
    ajaxRequest.open("GET","call.php?which="+a,true);
    ajaxRequest.send(); 
}

Apart from that,

/* in call.php after connection codes */
$came = $_GET['which'];
mysql_query("UPDATE ...");

Updates

I am using IE 9.0 (update version 9.0.10)

Also I added this code to call.php

header("Cache-Control: no-cache, must-revalidate");

Answer

After using cache-control and cache cleaning of browser it works good.

I believe the root cause - and possible solutions - are addressed by these links:

Apparently, IE "aggressively caches ajax requests". The above links should help you work around the problem.

PS:

What version of IE is experiencing this problem?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM