XMLHttpRequest in Ajax

XMLHttpRequest object is backbone of Ajax.XMLHttpRequest object is supported by all modern browsers.

XMLHttpRequest object is used to send HTTP or HTTPS requests to a web server and load the server response data back into your page.

Create XMLHttpRequest Object

var xhttpobject = new XMLHttpRequest(); // (IE7+, Opera ,Firefox, Safari,and Chrome) var xhttpobject = new ActiveXObject("Microsoft.XMLHTTP");//(IE5 and IE6)

List of XMLHttpRequest Methods

abort() abort method is used to cancel the current request.

getAllResponseHeaders() getAllResponseHeaders method returns the complete set of HTTP headers as a string.

open(method, url, async) open method is used to specifies the type of request.

send()send method is used to sends the request to the server using GET.

send(string)This method is used to sends the request to the server using POST.

Difference between async:false and async:true?

async:false Set async:false when you need that ajax request to be completed before the execution of other code.

async:true Set async:true allows your page to continue to be processed and handle ajax response when the response is ready in the onreadystatechange event.