Are there any AJAX gurus out there? I have a simple AJAX/PHP web app that works fine with Firefox but not with IE. Here's my javascript (copied almost verbatim from http://rajshekhar.net/blog/archives/85-Rasmus-30-second-AJAX-Tutorial.html):
function createRequestObject() {
var ro;
var browser = navigator.appName;
if(browser == "Microsoft Internet Explorer") {
ro = new ActiveXObject("Microsoft.XMLHTTP");
}
else{
ro = new XMLHttpRequest();
}
return ro;
}
var http = createRequestObject();
function sndReq(action) {
http.open('get', 'triptych_action.php?action='+action);
http.onreadystatechange = handleResponse;
http.send(null);
}
function handleResponse() {
if(http.readyState == 4){
var response = http.responseText;
var update = new Array();
if(response.indexOf('|' != -1)) {
update = response.split('|');
document.getElementById(update[0]).innerHTML = update[1];
}
}
}
So, I include this js in my php script and the sndReq() function gets called when the user clicks on a submit button like so:
<input type='submit' value='one.back' name='submit' onclick="javascript:sndReq('foo4')">
The backend script that processes the request is called triptych_action.php. It uses a switch statement like this:
switch($_REQUEST['action']) {
case 'foo4':
echo "a_div_tag|some_html";
break;
}
As noted above, everything works fine with Firefox. With IE however, everthing works fine the first time you click on any given submit button (i.e. the correct element is reloaded on the page) but after that--if you click the same button again--nothing happens. Very vexing!
The live page is here: www.imipolex.org/ajax/misc/triptych.php
Thanks in advance for any help/ideas.