Chrome プラグインで次のコードを使用して、クロスオリジン リクエストを作成し、ローカル ストレージに保存しています。
function Search(query) {
this.query = query;
this.fetch = function(callback) {
if (query) {
console.log(query);
// new cross origin XML request
xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4) {
if (xmlhttp.status == 200) {
this.searchResult = JSON.parse(xmlhttp.responseText);
console.log(this.searchResult);
callback(this.searchResult);
}
else
callback("noquery");
}
};
xmlhttp.open("GET", "xxxxxxx" + this.query, true);
xmlhttp.send();
}
else
callback("noquery");
};
this.save = function(results) {
chrome.storage.local.set({'searchResults': results});
console.log('results saved');
// save results
};
次のコードを使用して実行し、コールバック関数として searchResults.save() を渡そうとしています:
searchResults = new Search(currentSearchURL.query());
searchResults.fetch(searchResults.save());
ただし、コンソールに次のエラーが表示されます。
Uncaught TypeError: object is not a function background.js:35
xmlhttp.onreadystatechange
ここで私が間違っていることを誰かが見ていますか?