1. Home
  2. Computing & Technology
  3. JavaScript

Introduction to Ajax

9. Setting Response Type

clr gif

If the content on the server that you are going to retrieve is static then what is returned is rather obvious - response.xml contains XML and response.txt contains plain text. Where you are going to use a server side scripting language to generate the response then things are a little more complicated.

Whether the server returns XML or plain text depends on how the server side script is configured. How you configure the server side script depends on which language that it is that you are using on the server.

One language commonly used for the server side of AJAX is PHP. With PHP the content type is defined using the header function and the response is returned using echo.

<?
header("Content-Type: text/xml");
// code to generate $response
echo $response;
?>
Explore JavaScript
About.com Special Features

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

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. JavaScript

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

All rights reserved.