1. Home
  2. Computing & Technology
  3. JavaScript

Introduction to Ajax

8. responseText and responseXML

clr gif

In the last tutorial we looked at how we can determine whether the response is XML or plain text. The reason why we must know the answer to this (either by knowing what the server side script is set up to return or by testing the content type in our code) is that the response is returned in one of two different fields depending on which of these two formats it is that is being used.

The following code fragment illustrates these two fields by substituting alerts to display the appropriate field into the code from our last tutorial where we tested the content type.

if (cType == 'text/xml') {
alert(this.responseXML);
} else if (cType == 'text/plain') {
alert(this.responseText);
} else {
alert('unknown content type');
}
Explore JavaScript
About.com Special Features

Holiday Central

What to eat, where to go, fun things to do and how to save money on the perfect gifts. More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

  1. Home
  2. Computing & Technology
  3. JavaScript

©2009 About.com, a part of The New York Times Company.

All rights reserved.