issue with Ajax and IE
-
I'm using AJAX for the first time and while writing some code I noticed that IE appeared to be miss-behaving. Attached below is the test case showing the issue. This appears to fail with IE 6 and IE 7. Works fine with firefox and chrome. In the code I have a number of alerts showing the path through the code and everything works ok until (with IE only) the call to the call back function setOutput. With IE the second time the doAjax script is invoked, setOutput's never called (or at least there is never a ready state of 4). The way to reproduce this, is to delete IE's temporary internet files (tools/delete browsing history/temporary internet files). Load the test script test.html. Then click the "Click here" button and follow the path through. The first time it works fine and SetOutput is indeed called. If the button is clicked a second time, setOutput's never called. You can repeat this procedure (deleting browser history and clicking "click here"). I tried deleting the ajaxObject object to see if that would help, but it did not. All help appreciated, Thanks Phil <code> ---------------- test.html -------------------------------------- <head> <script language="javascript" type="text/javascript"> <!-- var ajaxObj = null; function getAjaxObj() { alert("getAjaxObj: Getting ajax object."); alert("getAjaxObj: req is " + typeof req); // native XMLHttpRequest object if(window.XMLHttpRequest && !(window.ActiveXObject)) { alert("1"); try { req = new XMLHttpRequest(); alert("1.1"); } catch(e) { &nbs
-
I'm using AJAX for the first time and while writing some code I noticed that IE appeared to be miss-behaving. Attached below is the test case showing the issue. This appears to fail with IE 6 and IE 7. Works fine with firefox and chrome. In the code I have a number of alerts showing the path through the code and everything works ok until (with IE only) the call to the call back function setOutput. With IE the second time the doAjax script is invoked, setOutput's never called (or at least there is never a ready state of 4). The way to reproduce this, is to delete IE's temporary internet files (tools/delete browsing history/temporary internet files). Load the test script test.html. Then click the "Click here" button and follow the path through. The first time it works fine and SetOutput is indeed called. If the button is clicked a second time, setOutput's never called. You can repeat this procedure (deleting browser history and clicking "click here"). I tried deleting the ajaxObject object to see if that would help, but it did not. All help appreciated, Thanks Phil <code> ---------------- test.html -------------------------------------- <head> <script language="javascript" type="text/javascript"> <!-- var ajaxObj = null; function getAjaxObj() { alert("getAjaxObj: Getting ajax object."); alert("getAjaxObj: req is " + typeof req); // native XMLHttpRequest object if(window.XMLHttpRequest && !(window.ActiveXObject)) { alert("1"); try { req = new XMLHttpRequest(); alert("1.1"); } catch(e) { &nbs
Hi The problem reported by you is a very genenal with IE. If you are making a AJAX call to server with same argument, then IE will not call the server page. It will display the previously fetched result. You can fix this bug with the little changes as: Every time you make a server call, send some Unique number along with the arguments. As you are just calling 'test.php' make the argument as test.php?rnd=<some random number> <some random number> : Replace it with Unique number. This will solve your problem. Simple way to generate the unique number id var dtDate = new Date(); var strDate = dtDate.getHours() + '' + dtDate.getMinutes() + '' + dtDate.getSeconds() + '' + dtDate.getMilliseconds(); Make a server call as test.php?rnd=strDate
Regards Aman Bhullar www.arlivesupport.com[^]
-
Hi The problem reported by you is a very genenal with IE. If you are making a AJAX call to server with same argument, then IE will not call the server page. It will display the previously fetched result. You can fix this bug with the little changes as: Every time you make a server call, send some Unique number along with the arguments. As you are just calling 'test.php' make the argument as test.php?rnd=<some random number> <some random number> : Replace it with Unique number. This will solve your problem. Simple way to generate the unique number id var dtDate = new Date(); var strDate = dtDate.getHours() + '' + dtDate.getMinutes() + '' + dtDate.getSeconds() + '' + dtDate.getMilliseconds(); Make a server call as test.php?rnd=strDate
Regards Aman Bhullar www.arlivesupport.com[^]
-
What I did is to build a small ajax library with a couple of commands that I use on a regular basis and then I had those commands automatically add the random information for me. Then, I never have to worry about that ever again :)
Preston Tech Director / Developer MetalBuilding.com