...

View Full Version : onreadystate working only with alert statement



vator
01-01-2009, 06:33 PM
In my app I use some autocomplete functionality.

In the code below, the the readyState function worke only when I have an alert statement in it. I can't figure out why this should work...
Please help!!!



var u = "http://localhost:8080/ReiseloggSpring2/autoGetCities.do?city=b";
var reqObj = new AjaxRequest(u);
var r = reqObj.getRequest();

function AjaxRequest(urlStr){
var req;
var url = urlStr;
this.status = new Boolean("false");
this.initRequest = initRequest;
this.getRequest = getRequest;
this.onreadystate = onreadystate;

function getRequest(){
req = this.initRequest();
req.open("GET", url, true);
req.onreadystatechange = this.onreadystate;

req.send(null);

return req;
}

function onreadystate(){ alert("IN READYSTATE")

if (req.readyState == 4) {
if (req.status == 200) {
if( req.responseText.length > 0){
this.status = "true";
}else{
this.clearTable();
this.completeTable.style.display="none";
}
}else if (req.status == 204){
this.clearTable();
}
}
}

function initRequest() {
if (window.XMLHttpRequest) {
return new XMLHttpRequest();
} else if (window.ActiveXObject) {
return new ActiveXObject("Microsoft.XMLHTTP");
}
}
}

A1ien51
01-03-2009, 01:36 AM
= this.onreadystate;
needs to be loose the this

= onreadystate;

Eric



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum