javascript中的以下代码给了我错误“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;
}
}
}
为什么 open 方法不将回调参数视为函数?
如果是这样,那么为什么我不能在 onstatechange 函数中调用它?
我如何使这项工作?