1
意外的標識錯誤,我適應了XMLHttpRequest
從this tutorial:的Javascript未捕獲的語法錯誤:在Chrome中調試
var request = new XMLHttpRequest();
request.open('GET', 'http://www.mozilla.org/', true);
request.onreadystatechange = function (aEvt) {
if (request.readyState == 4) {
if (request.status == 200)
console.log(request.responseText)
else
console.log('Error', request.statusText);
}
};
request.send(null);
我的代碼是:
var xhr = new XMLHttpRequest();
xhr.open("POST", "http://ting-1.appspot.com/submithandlertest", true);
xhr.onreadystatechange = function (aEvt) {
if (xhr.readyState == 4) {
if (xhr.status == 200)
console.log("request 200-OK");
chrome.browserAction.setBadgeText ({ text: "done" });
else
console.log("connection error");
chrome.browserAction.setBadgeText ({ text: "ERR" });
setTimeout(function() {
chrome.browserAction.setBadgeText({ text: "" });
}, 2000);
}
}
xhr.send(formData);
而Chrome調試器會在else
一個Uncaught SyntaxError: Unexpected identifier
錯誤。我究竟做錯了什麼?謝謝!