Saturday, November 20, 2010

AJAX-XMLHttpRequest Part3

(Link with the post AJAX-XMLHttpRequest 2 )

Finally a function useHttpResponse need to be written which will establish when the server has completed our request, and do something useful with the data it has returned:

function useHttpResponse() {
if (http.readyState == 4) {
var response = http.responseText;


Note here that the function checks for a readyState value of 4 - there are various numbered states describing the progress of such a request, but only value of 4 indicates that the request is complete and we can use the returned data.

In this case, the information has received as simple text via the responseText property of our XMLHTTPRequest object. Information can, however, be returned as XML ,JSON or as properties of a predefined javascript object.


No comments:

Post a Comment