我正在尝试为 chrome 扩展创建一个简单的 ajax 类。Uncaught TypeError: Cannot read property 'readyState' of undefined
尝试运行代码时出现未定义的错误 。似乎是什么导致了这个问题?
function ajax(arguments, callback) {
this.xhr = new XMLHttpRequest();
this.xhr.open(arguments.requestType, arguments.requestUrl + arguments.requestParameters, true);
this.xhr.onreadystatechange = function() {
if (this.readyState === 4 && this.status === 200) {
requestedData = JSON.parse(this.responseText);
callback(requestedData);
}
}
this.xhr.send();
}
var ajaxRequest = new ajax({
requestType: 'GET',
requestUrl: 'http://ezswag.com/bots/terms.php',
requestParameters: ' ',
}, function(json) {
//console.log(json); => json {apple: "red", cheery: "red"}
return json;
});
console.log(ajaxRequest);
(更新的代码和工作)