Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Browser Refresh Messing up Ajax

Status
Not open for further replies.

snached

Programmer
Mar 5, 2006
1
Hello.

I have a problem which I dont have a clue to what the cause if it could be.

If I go to my page on localhost it seems to work perfectly. When one of my friends go on my page through my webserver it works the first time they load it. But if they hit refresh then ajax does not load any components from the server. This problem only occurs on IE and not firefox.

Does anyone know what might be causing this problem? I use one XMLHttpRequest object and only ever make one ajax call at a time.

What is the difference between loading a page or refreshing it? Is there any important difference I should know of?


Here is a code snippet:

Code:
function loadHeader()
{
     xmlhttp=initXMLHttpRequest();
     xmlhttp.onreadystatechange=loadHeader_callback;
     xmlhttp.open("GET", url + "?request=loadHeader", true)
     xmlhttp.send(null)
}
function loadHeader_callback()
{
     if (xmlhttp.readyState==4) 
     {
          document.getElementById('divHeader').innerHTML =  xmlhttp.responseText;
     }
}



Thanks, Thomas Hoggard
 
Here is the code I use for my HTTPObject set up (branching code for IE)...
Code:
		function getHTTPObject() {
			var xmlhttp;
			/*@cc_on
			@if (@_jscript_version >= 5)
				try {
					xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
				} catch (e) {
					try {
						xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
					} catch (E) {
						xmlhttp = false;
					}
				}
			@else
				xmlhttp = false;
			@end @*/
			if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
				try {
					xmlhttp = new XMLHttpRequest();
				} catch (e) {
					xmlhttp = false;
				}
			}
			return xmlhttp;
		}
Maybe you aren't setting up your object properly in IE?

Cheers,
Jeff

[tt]Jeff's Page @ Code Couch
[/tt]

What is Javascript? FAQ216-6094
 
snached,

Did you ever solve this problem? I seem to have the same issue while updated records in a database. The database gets updated but if I request the info again the information I recieve appears to be cached.

Thanks
 
Ekbranson, I don't know if you tried this, but you can turn off caching for that page, if you don't want the page to be cached.

I don't know the answer but my good friend Google does.
 
In the action page (url), you have to set the cachecontrol of the response object to "no-cache". If the page is written in asp, you add this line at the beginning.
[tt] Response.CacheControl="no-cache"[/tt]
This is one of the plausible resolutions.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top