Basics of AJAX - Part 2
In the previous article we discussed on the concept of coding and methods getting used in Ajax Operation. In this we will go deep inside the XMLHttp Object and other issues on AJAX Programming.
XMLHttpRequest Object Methods:
- .open(methodname,url,mode of operation)
method - It can be GET or POST depending on the amount of data you want to send to the server.
url - Server path of the remote file name.
mode of operation - Accepts a boolean value indication Async/Sync mode of operation. True indicates Asynchrounous Mode whereas False indicated Synchronous Mode - .send(parameter)
In case of POST method send all the values as a parameter to the send method - .abort()
Abort the current AJAX call operation - .getAllResponseHeaders()
Returns all the header(labels & values) as a string - .getResponseHeader(Header Name)
Returns the value of the specified header name - .setRequestHeader(label,value)
Set the Header before sending the request
XMLHttpRequest Object Properties:
- .onreadystatechange
Event handler that gets fires at each state change - .status
Returns the HTTP status from the server - .responseText
Return the response data in string format from the server - .responseXML
Return the response data in XML format from the server
Example of using GET Method
xmlhttp.open("GET",url,true) xmlhttp.send(null)
Example of using POST Method
xmlhttp.open("POST",url, true); xmlhttp.setRequestHeader('Content-type','application/x-www-form-urlencoded;charset=UTF-8;'); xmlhttp.send('hello=world&XMLHttpRequest=test');
Here we setting the header for application data having character set as UTF-8. Also we are sending two variable hello and XMLHttpRequest having values world and test.
FAQ on AJAX:
- Sending data through querystring has limitation on number of characters so need to be careful while sending data. Needs to be decided in advance before sending data to the server
- If same AJAX object variable is used to call remote script then the old remote server call gets lost and is replaced by the server call. The solution to this problem is to used different variable for every ajax operation or implement a queue facility
Caching in AJAX
Browsers caches the data send through GET methods (i.e through querystring in Temporary Internet Folder). To overcome this situation following methods can be used.
- Add the timestamp in the querystring
- Use POST method so the variable will get processed at server end
Similar Posts
Did you enjoy this post? Why not leave a comment below and continue the conversation, or subscribe to my feed and get articles like this delivered automatically to your feed reader.


Thank you for sharing!