AJAX

What does AJAX stands for?
Asynchronous JavaScript and XML.

 
What can be achieved with AJAX?
From within JavaScript, you can send HTTP or HTTPS calls directly to a web server and load the server response data directly back into the script thus avoiding the page refreshes to get the server response.
Reference: XMLHttpRequest - Wiki

 
What JavaScript object is used in AJAX communication?
XMLHttpRequest.

 
What is XMLHttpRequest object's same origin policy?
XMLHttpRequest is subject to the browser's same origin policy in that, for security reasons, requests will only succeed if they are made to the same server that served the original web page. There are alternative ways to circumvent this policy if required.
Reference: XMLHttpRequest - Wiki

 
How do you make an AJAX call?
  • Create an XMLHttpRequest object
  • Initialize the object by invoking it's open method
  • Send an HTTP request by invoking it's send method
  • Check the readystate, status of the AJAX request through XMLHttpRequest object's onreadystatechange event listener
  • When readystate is 4 and status is 200, process the response

 
Give an example with the above steps?


 
What are the properties of XMLHttpObject?
  • readystate (0:uninitiated, 1:loading, 2:loaded, 3:interactive, 4:complete)
  • responsetext (Returns response data as a string)
  • responseXML (Returns response data as XML)
  • status (status of the request by number - 200, 304, 403, 404)
  • statusText (status of the request by name - "ok"(for 200),"Not modified" (for 304), "Forbidden" (for 403), "Not Found" (for 404)
  • contentType (helps to set/get the content type explicitly)
  • timeout (time allowed for the request to complete)
Read more:http://www.javascriptkit.com/jsref/ajax.shtml
Read more: http://www.javareference.com/jrexamples/viewexample.jsp?id=111
 
What are the methods of XMLHttpRequest object?
  • abort()
  • open(method, url, [[async], [username], [password])
  • send(data)
  • getResponseHeader(header)
  • getAllResponseHeaders()
  • setRequestHeader(header, value)
Read more:http://www.javascriptkit.com/jsref/ajax.shtml
Read more: http://www.javareference.com/jrexamples/viewexample.jsp?id=111
 
What are the events of XMLHttpRequest object?
  • onreadystatechange
  • onerror
  • onload
  • onprogress
  • ontimeout
Read more: http://www.javascriptkit.com/jsref/ajax.shtml
Read more: http://www.javareference.com/jrexamples/viewexample.jsp?id=111