Hi All, I've just bought the book and started with AJAX and already I'm banging my head in frustration. To try AJAx out I'm using the following code. It works just fine in IE but in FireFox I get nothing. No alert, no errors nothing. The worst bit is it is working in as much as the POSTDATA is sent and processed correctly but as soon as it moves into the callback function (handleResponse) I can't get anything out of it. Hope someone can see the flaw.
Code:
function createRequestObject() {
var ro;
var browser = navigator.appName;
if(window.ActiveXObject){
ro = new ActiveXObject("Microsoft.XMLHTTP");
}else{
ro = new XMLHttpRequest();
if (ro.overrideMimeType) {
ro.overrideMimeType('text/html');
}
}
return ro;
}
function sndReq(field,val) {
validate = createRequestObject();
globCurAJAXField = field;
validate.onreadystatechange = handleResponse;
validate.open('POST', 'updateDB.php');
validate.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
validate.send(###POSTDATA###);
}
function handleResponse() {
var result;
if(validate.readyState == 4){
if(validate.status == 200) {
result = validate.responseText
alert("result :" + result);
}
}
}