Ajax problem with IE ... IE doesn't update/refresh

Hi,

I have Ajax script that shows image after every test completion. It works and update just fine in all browsers except IE. IE only shows the first test and it doesn't update after that. I think it's a cache problem. I also confirmed that by searching on Google.

This is my current code. What should I do to bypass this IE problem?
function getTestID() {
                var xmlhttp = null;
                if(window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest(); } else{ xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); }
                if(xmlhttp != null) {
                        xmlhttp.open("GET","getid.php",false);
                        xmlhttp.send();
                        return xmlhttp.responseText;
                }
                return -1;
}


function test_completed(result1, results2) {
	var myid = getTestID(); 
        if(myid!=-1) {
	document.getElementById("mypic").innerHTML = "<img src='http://www.mywebsite.com/result/" + myid + ".png'><br>" + "Direct Link:<br><input type='text' readonly='readonly' size='37' value='http://www.mywebsite.com/result/" + myid + ".png'<br>" + "Forum Link:<br><input type='text' readonly='readonly' size='37' value='[URL=http://www.mywebsite.com][IMG]http://www.mywebsite.com/result/" + myid + ".png[/IMG][/URL]'<br>";

Open in new window

Dido123Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

LCARSx32Commented:
Try adding the following to your <head>:

[code]<META HTTP-EQUIV="Expires" CONTENT="Tue, 01 Jan 1980 1:00:00 GMT">
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">[/code]

HTH,

-Ray
0
Dido123Author Commented:
Is there any better solution? I found this one when I was searching on Google but I'm thinking that there might be a better one.
0
LCARSx32Commented:
I'm not sure?  Better how?

You could also use javascript: document.location = "yourpage.php".

Personally, I like meta refresh better as javascript can be turned off.  I've used it on several sites.  It even passes XHTML validation.  What's your concern with using it?

-Ray
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

leakim971PluritechnicianCommented:
Hello Dido123,

Replace your test_completed function by this one :


function test_completed(result1, results2) {
        var myid = getTestID(); 
        if(myid!=-1) {
			var url = "http://www.mywebsite.com/result/" + myid + ".png";

			var img = document.createElement("img");
			img.src = url;

			var br1 = document.createElement("br");
			var tn1 = document.createTextNode("Direct Link:");
			var br2 = document.createElement("br");			
			
			var input1 = document.createElement("input");
			input1.type = "text";
			input1.setAttribute("readonly","readonly");
			input1.setAttribute("size","37");
			input1.value = url;
			
			var br3 = document.createElement("br");
			var tn2 = document.createTextNode("Forum Link:");
			var br4 = document.createElement("br");
			
			var input2 = document.createElement("input");
			input2.type = "text";
			input2.setAttribute("readonly","readonly");
			input2.setAttribute("size","37");
			input2.value = "[URL=http://www.mywebsite.com][IMG]" + url + "[/IMG][/URL]";			

			var br5 = document.createElement("br");

			var mypic = document.getElementById("mypic")
			mypic.appendChild(img);
			mypic.appendChild(br1);
			mypic.appendChild(tn1);
			mypic.appendChild(br2);
			mypic.appendChild(input1);
			mypic.appendChild(br3);
			mypic.appendChild(tn2);
			mypic.appendChild(br4);
			mypic.appendChild(input2);
			mypic.appendChild(br5);
		}
}

Open in new window

0
Dido123Author Commented:
leakim971, awesome as usual! :)

One more request ...

How I add this line code to the new code? I used it in the old functions.js to report to Google Analytics that test completed ....


Thank you so much for your great support.
+ pageTracker._trackPageview('/done/');

Open in new window

0
leakim971PluritechnicianCommented:
what's your previous integration ?
0
Dido123Author Commented:
At the end of the old function :
function test_completed(result1, results2) {
        var myid = getTestID(); 
        if(myid!=-1) {
        document.getElementById("mypic").innerHTML = "<img src='http://www.mywebsite.com/result/" + myid + ".png'><br>" + "Direct Link:<br><input type='text' readonly='readonly' size='37' value='http://www.mywebsite.com/result/" + myid + ".png'<br>" + "Forum Link:<br><input type='text' readonly='readonly' size='37' value='[URL=http://www.mywebsite.com][IMG]http://www.mywebsite.com/result/" + myid + ".png[/IMG][/URL]'<br>"; + pageTracker._trackPageview('/done/');

Open in new window

0
leakim971PluritechnicianCommented:
Try :


function test_completed(result1, results2) {
        var myid = getTestID(); 
        if(myid!=-1) {
                        var url = "http://www.mywebsite.com/result/" + myid + ".png";

                        var img = document.createElement("img");
                        img.src = url;

                        var br1 = document.createElement("br");
                        var tn1 = document.createTextNode("Direct Link:");
                        var br2 = document.createElement("br");                 
                        
                        var input1 = document.createElement("input");
                        input1.type = "text";
                        input1.setAttribute("readonly","readonly");
                        input1.setAttribute("size","37");
                        input1.value = url;
                        
                        var br3 = document.createElement("br");
                        var tn2 = document.createTextNode("Forum Link:");
                        var br4 = document.createElement("br");
                        
                        var input2 = document.createElement("input");
                        input2.type = "text";
                        input2.setAttribute("readonly","readonly");
                        input2.setAttribute("size","37");
                        input2.value = "[URL=http://www.mywebsite.com][IMG]" + url + "[/IMG][/URL]";                    

                        var br5 = document.createElement("br");
                        var tn3 = document.createTextNode( pageTracker._trackPageview('/done/') );

                        var mypic = document.getElementById("mypic")
                        mypic.appendChild(img);
                        mypic.appendChild(br1);
                        mypic.appendChild(tn1);
                        mypic.appendChild(br2);
                        mypic.appendChild(input1);
                        mypic.appendChild(br3);
                        mypic.appendChild(tn2);
                        mypic.appendChild(br4);
                        mypic.appendChild(input2);
                        mypic.appendChild(br5);
                        mypic.appendChild(tn3);
                }
}

Open in new window

0
Dido123Author Commented:
I tested it out first in Firefox and I got two problems:

1. It gives me "undefined" below Forum Link .. I'm sure it's from the Google Analytics line isn't executing correctly.

2. When I do "restart test" the new results show below the current one. It doesn't replace it.
0
Dido123Author Commented:
I also tried it in IE and I noticed that the duplicated results are all the same, which means that IE problem still not solved.
0
Dido123Author Commented:
I just solved my problem! :D

I used the solution from this question : http://www.experts-exchange.com/Programming/Languages/Scripting/AJAX/Q_24483879.html

Basically, all what I did is replacing this line :

xmlhttp.open("GET","getid.php",false);

with this :

xmlhttp.open("GET","getid.php?cachebuster=" + new Date().getTime(), false);
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
leakim971PluritechnicianCommented:
Great!
0
Dido123Author Commented:
@leakim971 .. thanks

here is a new related question for you : http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_25833686.html
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
AJAX

From novice to tech pro — start learning today.