here is my code snippet.
Expand|Select|Wrap|Line Numbers
- function AjaxAgent(){
- var xhr = null;
- var isReadyState = true;
- //CODE SNIPPED
- this.postRequest = function(){
- // CODE SNIPPED
- xhr = getHTTPObject();//get the HTTPObject
- if(xhr){
- xhr.onreadystatechange = function(){
- if(xhr.readyState == 4){
- isReadyState = true;
- if(xhr.status != 200 && xhr.status != 304){
- alert("ERROR");
- }
- }
- };
- xhr.open("POST", URL, true);
- xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
- xhr.send(queryStr);
- }
- };
- this.getXMLElemSize = function(elemName,httpObj){
- if(httpObj==null)httpObj=xhr;
- //alert(isReadyState)
- if(!isReadyState){
- return myself.getXMLElemSize(elemName,httpObj);
- }else{
- if(XMLResp == null) XMLResp = xhr.responseXML;
- return XMLResp.getElementsByTagName(elemName).length;
- }
- };
- }
I'm writing a somesort of a common ajax class. For e.g.
Expand|Select|Wrap|Line Numbers
- var aa = new AjaxAgent();
- ...
- ...
- aa.postRequest();
- alert(aa.getXMLElemSize("Name"));
and that is why in the method getXMLElemSize i try to call the function recursively.. till XMLHttp object readystate is 4. But the problem is I'll hit "Stack Overflow at line:xx " error.
The funny thing is when I put an alert message in the method getXMLElemSize(say line 27 in the 1st code snippet), everything works out just fine.
I've been scratching my head since the last 2days just to solve this problem.
You guys have any idea? Any workaround for getting asynchronous response?