The following code in javascript gives me the error "this.callback is not a function
function ajaxRequest()
{
var httpObject;
this.open = open;
this.callback = function(){};
function getHTTPObject()
{
if (window.ActiveXObject)
return new ActiveXObject("Microsoft.XMLHTTP");
else if (window.XMLHttpRequest)
return new XMLHttpRequest();
else
{
alert("Your browser does not support AJAX.");
return null;
}
}
function onstatechange()
{
if(httpObject.readyState == 4)
{
this.callback(httpObject.responseText);
}
}
function open(url, callback)
{
httpObject = getHTTPObject();
if (httpObject != null)
{
httpObject.open("GET", url, true);
httpObject.send(null);
this.callback = callback;
httpObject.onreadystatechange = onstatechange;
}
}
}
why doesn't open method treat the callback parameter as function?
If it does then why can't i call it in onstatechange function?
How do i make this work?