- Asynchronous Javascript and XML
- Primary use is to update small section of webpage without reloading entire page eg: search box
- Browser sends request to the server with out changing the page
- The server will receive the page and send the processed results to client browser
- The client browser receives the results and presents to user.
Object XMLHttpRequest is used to interact with server. It is used to send the request to server as well as to receive response from the server
Following are the properties and methods of XMLHttpRequest
- readyState: it is used to determine the current status of the request
- status: it specifies if request was successful or not
- 200: OK i.e request was successful
- 404: page was not found
- Onreadystatechange: This is an event handler where a call back function can be registered. It holds a function which runs(called/invoked) everytime the value of readyState changes(it will get called 4 times for a successful ajax call)
- open(method, server url, asynchronous) : used to specify the connection parameters. method is the type of method(GET/POST), asynchrounous is to tell weather it is synchronous or asynchronous call
- send(): send() for GET Method or send(data) for POST method
- In case of Post request, contentType header has to be set on the header. This indicates how the request body is encoded. Browsers always encode post data as application-x-www-form-urlencoded
setRequestHeader("Content-type", "application/x-www-form-urlencoded");

No comments:
Post a Comment