I am facing an issue with the onreadystatechange while making an ajax request. Previously, it would call the processRequest function successfully but now it seems to be malfunctioning.
I'm uncertain if I inadvertently made any changes or modifications that caused this problem. Can someone offer assistance?
function createAjaxObject(url, callback)
{
/// @par Implementation
var req = init();
req.onreadystatechange = processRequest;
/// @brief Creates a new ajax object based on the running browser
function init()
{
if (window.XMLHttpRequest)
return new XMLHttpRequest();
else if (window.ActiveXObject)
return new ActiveXObject("Microsoft.XMLHTTP");
}
/// @brief Checks if the request is complete and HTTP call is successful
function processRequest ()
{
/// A readyState of 4 signifies a completed request
if (req.readyState == 4){
/// A status of 200 indicates a successful HTTP call
if (req.status == 200){
if (callback)
callback(req.responseXML);
}
}
}
this.doPost = function(param) {
if (req.readyState == 4) {
/// Make an asynchronous HTTP POST request to the specified URL
req.open("POST",url, true);
req.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
req.setRequestHeader("Content-length",param.length);
req.setRequestHeader("Connection", "close");
req.send(param);
}
}
}
Thank you,