Search
Left Quote    By failing to prepare, you are preparing to fail.
- Benjamin Franklin    
Right Quote
 
[login] | [Register]
 

Getting Started with Ajax

by: misterhaan
Page: 1 of 4
(View All)

Using Ajax


Ajax is an acronym for asynchronous javascript and xml. The important part of this name is asyncronous javascript

XMLHttpRequest Object


Practically everything happens through an XMLHttpRequest object. The first step is creating one. Most browsers support new XMLHttpRequest() but older versions of internet explorer (technically msxml libraries used by internet explorer) required creating an ActiveXObject. To handle both the current method and two older msxml methods, as well as browsers that don

Ajax Requests

Ajax requests should usually be sent to the same server that served the page the Ajax JavaScript is running on, which means the ajax response will also come from that same server. The simplest case is responding with a static file (probably an xml or txt file), in which case all that needs to be done on the server is to make sure the file is in place. More often though it will be necessary to run a script on the server to process the data sent with the request and respond appropriately.


Headers


A consideration with using php (or any other server-side language) is that the server is probably set to send headers saying php output is html. With Ajax you may sometimes be using html, but often xml or plain text is more appropriate. For those cases, you should send the appropriate header for the format of the response. In php, this is done with the header function. other server-side languages have similar functions.

The header needed is Content-Type. For xml you want the value set to text/xml, and for plain text text/plain. it

Handling the Response

The final piece to an Ajax feature is to do something based on the response. This is done in the JavaScript function called in the readystatechange event handler. Two more properties of the XMLHttpRequest object are useful at this point: responseText and responseXml. Generally, one or the other fits

1  |  2  |  3  |  4  |  
Next »


No Comments for this page.

You Must be logged in or a member to comment.


Tutorial Stats

Tutorial Stats

11,406 Views
0 Total Comments
5 Rating of 5 (1 Votes)

Options

Tutorial Options

· Login to Rate This Article
· Login to Post a Comment
· Read more by this author
Digg This Article! Del.icio.us: Bookmark This Article Reddit: Bookmark This Article BlinkList: Blink This Article! YahooMyWeb BlogMarks: Add This Mark! Furl: Save This Article Spurl: Mark This Article

Articles

Related    

· Learning JavaScript Basics
Your Article Here



"AllSyntax.com" Copyright © 2002-2017; All rights lefted, all lefts righted.
Privacy Policy  |  Internet Rank