Javascript Uncaught SyntaxError: Unexpected identifier error in Chrome debugger -
i adapting xmlhttprequest
this tutorial:
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);
my code is:
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);
but chrome debugger gives uncaught syntaxerror: unexpected identifier
error on else
. doing wrong? thanks!
you missing closing }
before , opening {
after else, other ones in if-else - statement.
it works on tutorial code, because there's 1 line in if-else - statement. when there multiple lines, have block them correctly. (i recommend always, if there's 1 line of code. in opinion adds readability , not have problems, when decide minify code 1 day)
try this:
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);
Comments
Post a Comment