JavaScript XMLHttpRequest open Method: Calling a URL in Ajax

If this post helps you, click an ad

In JavaScript, to call a URL for usage in an Ajax application, an XMLHttpRequest object must be created. This was described in a previous post:

JavaScript: Creating XMLHttpRequest object for Ajax

Once the XMLHttpRequest (XHR) object is created, a URL can be called by using the XHR’s open method, as follows:

objXHR.open('GET','http://myURL.com',true);

The three parameters passed to the open method are as follows:

1: The method by which the HTTP should be retrieved: GET or POST
2: The requested URL. A relative or absolute URL may be used here. If an absolute URL is being used, most browsers implement a same-origin policy, meaning the URL being requested must be on the same domain as the domain from which the URL is being requested.
3: How the request should be issued: True for asynchronous; False for synchronous.

After the XHR object has opened a request, send the request.

One Response to “JavaScript XMLHttpRequest open Method: Calling a URL in Ajax”

  1. Hugo de Luna Says:

    The “async” parameter (3rd parameter) specifies whether the request should be handled asynchronously or not – “true” means that script processing carries on after the send() method, without waiting for a response, and “false” means that the script waits for a response before continuing script processing.

    Source: Wikipedia

Leave a Reply