HTTP GET request in JavaScript?

I need to do an HTTP GET request in JavaScript. What's the best way to do that?

I need to do this in a Mac OS X dashcode widget.

Text Copied From
on : Wed, Oct 29, 2008 Views : 1184188

Accepted Answer

You can use functions provided by the hosting environment through javascript:

function httpGet(theUrl) 

  var xmlHttp = new XMLHttpRequest(); GET, theUrl, false );
// false for synchronous request
  xmlHttp.send( null );

  return xmlHttp.responseText;

However, synchronous requests are discouraged, so you might want to use this instead:

function httpGetAsync(theUrl, callback) 

  var xmlHttp = new XMLHttpRequest();

  xmlHttp.onreadystatechange = 

   if (xmlHttp.readyState == 4 &
 xmlHttp.status == 200)

}, theUrl, true);
// true for asynchronous

Note: Starting with Gecko 30.0 (Firefox 30.0 / Thunderbird 30.0 / SeaMonkey 2.27), synchronous requests on the main thread have been deprecated due to the negative effects to the user experience.

Text Copied From
on : Wed, Oct 27, 2010

Ask Question

If you want to ask question you must LogIn or SignUp
Login SignUp

Quick Links



Total Followers
Study Group Created
Study Group Joined
Following Teacher
Following Organization
Blog Articles Added
Questions Asked
Questions Answered
Jobs Posted
Total Members in Group
Questions asked by members
Tasks added in this Group

Please wait..


Login to Open ESchool OR Create your account    Login   SignUp