Jump to content

New to Ajax - IE issue


SharkBait

Recommended Posts

Ok I followed the tutorial on the aJaxFreaks with updating live content or somehting (this one? http://www.ajaxfreaks.com/tutorials/2/0.php)

Anyway I have my code updating on Firefox, but IE doesn't seem to want to update. Unless I close the browser and open the browser.... even with a shift-refresh it doesn't want to update.

This is my ajaxFuncs.js file:
[code]
function createRequestObject() {
var req;

if (window.XMLHttpRequest) {
// Firefox, Safari, Opera
req = new XMLHttpRequest();
} else if (window.ActiveXObject) {
// IE 5+
req = new ActiveXObject("Microsoft.XMLHTTP");
} else {
// Cannot create object
alert("There was a problem creating the XMLHttpRequest object");
}

return req;

}

var http = createRequestObject();

function sendRequest(act) {
// Open PHP script for requests
http.open('get', 'show_daily_count.php');
http.onreadystatechange = handleResponse;
http.send(null);
}

function handleResponse() {
if (http.readyState == 4 && http.status == 200) {
// Text returned FROM PHP script
var response = 0;
var response = http.responseText;

if (response) {
// UPDATE content
document.getElementById("counterTable").innerHTML = response;
// Refresh every 10 secs
setTimeout(counterTable, 1000);
}
}

}

function counterTable() {
sendRequest('counterTable');
}
[/code]

I call the counterTable() function on the body's onload().  the show_daily_count.php just echo's a table that has been filled by MySQL data.

Is there something special I need to do to my headers for IE to get this to work?  Not have it read from the cache or something?



Link to comment
Share on other sites

That is what someone told me to do :P

I'm not sure where I put the bit of code then.

I'm trying to update a table query on the fly so the user doesn't have to refresh the page. No need to click a button or anything just have the page do it.

Link to comment
Share on other sites

IE gives me nothing in the way of errors. It doesn't seem to refresh like Firefox does. You can highlight the text in firefox and it removes the highlight when it refreshes.

IE just stands and acts dumb :)  Could it be a caching issue with IE? When I manuall update the page is doesn't update the table either....if that helps at all

Link to comment
Share on other sites

Hello.

I've had this problem alot when working with AJAX in IE and updating contents from databases. I usually just fix it by putting a non-cache header in my PHP script, like below:

[code]
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
[/code]

On MSDN it also says:

[quote]
Microsoft Internet Explorer caches the results of HTTP GET requests in the Temporary Internet Files (TIF) folder. In most cases, caching improves performance for data that will not change frequently. To guarantee that the results are not cached, use POST.
[/quote]

..

[code]
// Refresh every 10 secs
setTimeout(counterTable, 1000);
[/code]

is one second tho :D.

[quote]iTimerID = window.setTimeout(vCode, iMilliSeconds [, sLanguage])[/quote]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.