After making a AJAX request from .js file the readystate propertyof the Http object is not changing

M

Mathan Babu

Hello,

Once the AJAX request is fired the readystate property remain as 1. It
never gets changed and the callback method is not firing as a result the
..aspx page is not being rendered.

The two functions that is involved in the above mentioned issues are
placed below:

fn #1

function ajax_SendRequest(fullUrl, callback)
{
var xmlHttp = CreateXmlHttpObject();

var url = fullUrl.split('?')[0];
var params = fullUrl.split('?')[1];

//Use post method in case data send to server exceed limit.
xmlHttp.open("POST", url, /* async = */ true);
xmlHttp.onreadystatechange = function() {
_ajax_HandleResponse(xmlHttp, callback); setCursorToArrow();}

xmlHttp.setRequestHeader("Content-type",
"application/x-www-form-urlencoded");
xmlHttp.setRequestHeader("Content-length", params.length);
xmlHttp.setRequestHeader("Connection", "close");

if (currentXmlHttp != null)
{
pendingRequests.push(xmlHttp);
pendingRequestsContent.push(params);
}
else
{
currentXmlHttp = xmlHttp;
xmlHttp.send(params);
}
}

fn #2

function _ajax_HandleResponse(xmlHttp, callback)
{

if (xmlHttp.readyState != 4)
{
// Not finished yet; do nothing
}
else if (xmlHttp.status != 200)
{
if( xmlHttp.status != 0 ) // Not aborted
{
_ajax_ReportError("AJAX request failed with HTTP code " +
xmlHttp.status + " : " + xmlHttp.statusText);
}
}
else
{
var dom = xmlHttp.responseXml;
var err = dom.parseError;

if (err.errorCode != 0)
{
_ajax_ReportError(err.reason + "\nXML context: " +
_ajax_FocusSubString(err.srcText, err.linepos));
}
else
{
var root = xmlHttp.responseXML.selectSingleNode("root");

if (! root)
{
_ajax_ReportError("XML was valid but did not have the expected
'root' document element");
}
else
{
_ajax_UnpackResponse(root);
if(root.selectSingleNode('content') &&
root.selectSingleNode('content').attributes.getNamedItem('ErrorCode'))
callback = null;

if (callback)
{
callback(root);
}

var fn = document.body.onresize; // Yes, we have to alias this.
No, we don't know why.
if (fn) fn();
}
}
}
if (pendingRequests.length > 0)
{
currentXmlHttp = pendingRequests.shift();
currentXmlHttp.send(pendingRequestsContent.shift());
}
else
{
currentXmlHttp = null;
}
}


Thanks,
Mathan.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top