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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Content doesn't reload into div in IE

Status
Not open for further replies.

kyern

Programmer
Mar 30, 2006
36
US
I have a really odd problem. I have a script that works in Firefox but doesn't in IE. There are no errors in firebug.

All it does is make a request to a page to see if there are any new items, if the value is greater than the one stored then it makes a new request for the content. I am running out of ideas on what I can do to make this work in IE.

Thank You!

David

Code:
		var whiteboard_total = 0;
		
		function makeRequest(url) {
	        var http_request = false;

	        if (window.XMLHttpRequest) { // Mozilla, Safari, ...
	            http_request = new XMLHttpRequest();
	            if (http_request.overrideMimeType) {
	                http_request.overrideMimeType('text/xml');
	            }
	        } else if (window.ActiveXObject) { // IE
	            try {
	                http_request = new ActiveXObject("Msxml2.XMLHTTP");
	            } catch (e) {
	                try {
	                    http_request = new ActiveXObject("Microsoft.XMLHTTP");
	                } catch (e) {}
	            }
	        }

	        if (!http_request) {
	            alert('Giving up :( Cannot create an XMLHTTP instance');
	            return false;
	        }
	        http_request.onreadystatechange = function() { checkTotal(http_request); };
	        http_request.open('GET', url, true);
	        http_request.send("");
	    }
		
		function checkTotal(http_request) {
	        if (http_request.readyState == 4) {
	            if (http_request.status == 200) {
					if (whiteboard_total >= 0) {
						temp_total = parseInt(http_request.responseText);
						if (temp_total > whiteboard_total) {
							whiteboard_total = temp_total;
							var random_num = (Math.round((Math.random()*1000)+1))
							var url = "whiteboard_output.asp?division=[%division%]&random=" + random_num
							getContent(url);
						}else{
							whiteboard_total = temp_total;
						}
					}
					setTimeout("makeRequest('whiteboard_total.asp?division=[%division%]')", 5000);
	            } else {
	                alert('There was a problem with the request.');
	            }
	        }
	    }
		
		function getContent(url) {
	        var http_request = false;

	        if (window.XMLHttpRequest) { // Mozilla, Safari, ...
	            http_request = new XMLHttpRequest();
	            if (http_request.overrideMimeType) {
	                http_request.overrideMimeType('text/xml');
	            }
	        } else if (window.ActiveXObject) { // IE
	            try {
	                http_request = new ActiveXObject("Msxml2.XMLHTTP");
	            } catch (e) {
	                try {
	                    http_request = new ActiveXObject("Microsoft.XMLHTTP");
	                } catch (e) {}
	            }
	        }

	        if (!http_request) {
	            alert('Giving up :( Cannot create an XMLHTTP instance');
	            return false;
	        }
	        http_request.onreadystatechange = function() { updateContents(http_request); };
	        http_request.open('GET', url, true);
	        http_request.send(null);
	    }
		
		function updateContents(http_request) {
	        if (http_request.readyState == 4) {
	            if (http_request.status == 200) {
					document.getElementById("content").innerHTML = http_request.responseText;
					self.focus();
	            } else {
	                alert('There was a problem with the request.');
	            }
	        }
	    }
		window.onload = function() { makeRequest('whiteboard_total.asp?division=[%division%]'); };
 
sounds like it might be my problem too.

as a temp fix, in IE, go to tools/internet options/settings

select the first radio button "everytime I vist the page"

and close IE, open IE and try your page again.

I agree, I would like a fix to this issue as opposed to a bandaid.
 
I think I know what the problem is. As justride said:
as a temp fix, in IE, go to tools/internet options/settings
select the first radio button "everytime I vist the page"

You request to the AJAX url is being cached, to force it to renew everytime, pass a timestamp in the query string of the URL, where timestamp is just the current date and time.

Code:
var now = new Date();
url = url + "?tstamp=now";

I came across this a few months back, it was a pain.
Hope that helps.



<.

 
Thank you for your suggestion, the problem is that I am already doing just that:

Code:
var random_num = (Math.round((Math.random()*1000)+1))
var url = "whiteboard_output.asp?division=[%division%]&random=" + random_num

To make sure it wasn't cached I've added headers tried forcing no cache through the calling asp page anything and I can't get it to work the way I want in IE.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top