Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6680755
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:30:43+00:00 2026-05-26T04:30:43+00:00

I am adapting the XMLHttpRequest from this tutorial : var request = new XMLHttpRequest();

  • 0

I am adapting the XMLHttpRequest from 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 a Uncaught SyntaxError: Unexpected identifier error on the else. What am I doing wrong? Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T04:30:44+00:00Added an answer on May 26, 2026 at 4:30 am

    You are missing the closing } before and the opening { after the else, as well as the other ones in your if-else – statement.

    It works on your tutorial code, because there’s only one line in the if-else – statement. When there are multiple lines, you have to block them correctly. (I personally recommend to do this always, even if there’s just one line of code. In my opinion it adds to readability and you will not have problems, when you decide to minify your code one 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);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm adapting the coding style guide from this source: http://www.csharpfriends.com/articles/getarticle.aspx?articleid=336 Under 5.2 Initialization, it
Im a bit new to T-SQL, Coming from a MySQL background Im still adapting
I have a sectioned UITableView using dictionaries adapting code from a tutorial (I don't
I wrote this simple test code, by adapting a piece from a book, to
I'm adapting the authentication system from Rails 3 Tutorial by Michael Hartl to better
What's the best practise when adapting C-style functions which return a true/false to Java?
I have the following jQuery which I need adapting: $(document).ready(function(){ $(.rss-popup a).hover(function() { $(this).next(em).stop(true,
I have an activex plugin here: http://reboltutorial.com/plugins/logo-badge/ I tried by adapting the script http://forums.devarticles.com/javascript-development-22/detecting-activex-objects-installed-in-ie-11041.html
I'm following a tutorial for a menu bar and I'm having trouble adapting it
I'm having issues with the following menu. I've been adapting a script from kirupa

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.