What is AJAX?

AJAX, an acronym for AsynchronousJavaScript and XML, is a web development technique for creating interactive web applications. The intent is to make web pages feel more responsive by exchanging small amounts of data with the server behind the scenes, so that the entire web page does not have to be reloaded each time the user makes a change. This is meant to increase the web page's interactivity, speed, and usability.

Using the XmlHttp object to retrieve the data

The valid list of XMLHttpRequest ready states is listed in the following table:

Value

Description

0

Uninitialized

1

Loading

2

Loaded

3

Interactive

4

Complete

The list of status codes for the HTTP status is given below:

1xx Informational

Request received, continuing process.

100: Continue

101: Switching Protocols

2xx Success

The action was successfully received, understood, and accepted.

200: OK

201: Created

202: Accepted

203: Non-Authoritative Information

204: No Content

205: Reset Content

206: Partial Content

207: Multi-Status

3xx Redirection

The client must take additional action to complete the request.

300: Multiple Choices

301: Moved Permanently. This and all future requests should be directed to another URI.

302: Found this the most popular redirect code, but also an example of industrial practice contradicting the standard. HTTP/1.0 specification (RFC 1945) required the client to perform a temporary redirect (the original describing phrase was "Moved Temporarily"), but popular browsers implemented it as a 303 See Other. Therefore, HTTP/1.1 added status codes 303 and 307 to disambiguate between the two behaviors. However, majority of web applications and frameworks still use the 302 status code as if it were the 303.

303: See Other (since HTTP/1.1). The response to the request can be found under another URI using a GET method.

307: Temporary Redirect (since HTTP/1.1). In this occasion, the request should be repeated with another URI, but future requests can still be directed to the original URI. In contrast to 303, the original POST request must be repeated with another POST request.

4xx Client Error

The request contains bad syntax or cannot be fulfilled.

400: Bad Request

401: Unauthorized. Similar to 403/Forbidden, but specifically for use when authentication is possible but has failed or not yet been provided. See basic authentication scheme and digest access authentication.

402: Payment Required. The original intention was that this code might be used as part of some form of digital cash/micropayment scheme, but that has not happened, and this code has never been used.

403: Forbidden

404: Not Found

405: Method Not Allowed

406: Not Acceptable

407: Proxy Authentication Required

408: Request Timeout

409: Conflict

410: Gone

411: Length Required

412: Precondition Failed

413: Request Entity Too Large

414: Request-URI Too Long

415: Unsupported Media Type

416: Requested Range Not Satisfiable

417: Expectation Failed

449: Retry With A Microsoft extension: The request should be retried after doing the appropriate action.

5xx Server Error

The server failed to fulfill an apparently valid request.

500: Internal Server Error

501: Not Implemented

502: Bad Gateway

503: Service Unavailable

504: Gateway Timeout

505: HTTP Version Not Supported

509: Bandwidth Limit Exceeded. This status code, while used by many servers, is not an official HTTP status code.

Hello Sathesh! I found your example very informative. But there persists a problem. I virtually know nothing of VB and its directives and syntaxes. I am conversant in C#. It would greatly benefit, if you kindly provided me with the respective C# versions for the server side codings of the pages WebForm2.aspx.vb and WebForm1.aspx.vb from your application. There are several things that I am at a loss with. For eg. when trying out the eg, in C#, the compiler prompts errors for missing out on some directives/assemblies which would be required for using classes like XmlNodeList( the one used in your sample for declaring the variable xlist) etc.
Also there are some other things that I would like to consult with you. Eg. where does the parameter 'countryNode' come from for the method ClearandSetStateListItems(). There's more. In the code beside pages you have used the variable xmlDoc, but without declaring it anywhere beforehand. Please explain.
All in all, although the sample is quite good, I haven't been able to apply it to my full satisfaction. Kindly provide me with the corresponding C# encoded Version for this example ASAP. Mail ID---sw6boy@yahoo.co.in. Thank you.

I'm afraid that there are several publically available libraries which exist which handle the sending and response of the XML more efficiently than the examples here.

Using try catch to work out which transport object is available in JS is a lazy and inefficient way of doing things - instead you can check if the object is null or its type is undefined - both of which are far more efficient than using error handling to achieve the same.

In addition, you should be aware that ASP.Net Ajax now uses JSON responses to retrieve its data - purely because it requires less bandwith; thus if you're sending back a BIG list of items, JSON is likely to be far more compressed than XML will be.

You also missed out other versions of the XML parser for IE which offer greater functionality for XSLT and XML DOM operations for browsers that support them.

Finally, the ASP.Net toolkit, although not the greatest piece of programming in the world due its over-coded nature and bugs does provide a mechanism not only to populate drop downs, but also cascading drop downs and is built in for free server-side.

I'd recommend that programmers who aren't that familiar with JavaScript (i.e. have only ever copied and pasted other peoples' code) should use this in preference to this solution.

Hello I am trying a sample application using AJAX as you have guided. I thought to add more like City List in the one which you made. But I am getting some errors in that The Following things I have tried.

1. Added cities in the xml file likeMaharashtraMumbaiPune

And added one more function on statechanged But things are not workign for me.
If you can help me please