Introduction to Ajax7. Response Type |
|
Join the DiscussionMore of this FeatureXMLHttpRequest Open Request Response Event Handler Send the Request Passing Parameters Success or Failure If you are the one creating the entire AJAX application then you ought to know exactly what format you expect to get your response in. We can of course confirm this by checking the content type defined in the response headers. Normally the response that we are expecting to get back will be either an XML or a plain text format so we can test which of these that we have using the following code:
ajaxObj.processRequest = function() {
if (this.readyState == 4) { if (this.status != 200) { alert('Error : Status '+this.status+' returned.'); } else { var cType = this.getResponseHeader("Content-Type"); if (cType == 'text/xml') { // XML response } else if (cType == 'text/plain') { // plain text response } else { alert('unknown content type'); } } } } |

