Academic Tutorials



English | French | Portugese | German | Italian
Google

Home Source Codes E-Books Downloads Contact Us About Us

AJAX Tutorial
AJAX Introduction
AJAX Example
AJAX Browsers
AJAX Source
AJAX Server
AJAX Database
AJAX XML
AJAX XMLHTTPRequest

HTML Tutorials
HTML Tutorial
XHTML Tutorial
CSS Tutorial
TCP/IP Tutorial
XML Tutorials
XML Tutorial
XSL Tutorial
XSLT Tutorial
DTD Tutorial
Schema Tutorial
XForms Tutorial
XSL-FO Tutorial
XML DOM Tutorial
XLink Tutorial
XQuery Tutorial
XPath Tutorial
XPointer Tutorial
RDF Tutorial
SOAP Tutorial
WSDL Tutorial
RSS Tutorial
WAP Tutorial
Web Services Tutorial
Browser Scripting
JavaScript Tutorial
VBScript Tutorial
AJAX Tutorial
DHTML Tutorial
HTML DOM Tutorial
WMLScript Tutorial
E4X Tutorial
Server Scripting
ASP Tutorial
PHP Tutorial
PERL Tutorial
SQL Tutorial
ADO Tutorial
.NET (dotnet)
Microsoft.Net
XML Web Services
ASP.Net
.Net Mobile
C# : C Sharp
ADO.NET
VB.NET
Multimedia
SVG Tutorial
Flash Tutorial
Media Tutorial
SMIL Tutorial
Web Building
Web Browsers
Web Hosting
W3C Tutorial
Web Building
Web Quality
Web Semantic
Web Careers
Java Tutorials
Java Tutorial
JSP Tutorial
Servlets Tutorial
Struts Tutorial
EJB Tutorial
JMS Tutorial
JMX Tutorial
Programming Langauges
C Tutorial
C++ Tutorial
Visual Basic Tutorial
Data Structures Using C
Soft Skills
Communication Skills
Time Management
Project Management
Team Work
Leadership Skills
Corporate Communication
Negotiation Skills


AJAX XMLHTTPRequest

Previous Next


  • The XMLHttpRequest object makes AJAX possible to take the request from the user and given to the server.



  • The XMLHttpRequest

    To create web applications in AJAX you have to become familiar with the JavaScript object called the XMLHttpRequest.

    The XMLHttpRequest object is the main key to AJAX. It has been available since Internet Explorer 5.5 was released in July 2000, but not fully discovered before people started to talk about AJAX and Web 2.0 in 2005.

    Below is given some of the methods and properties you have to become familiar with.

    Creating An XMLHttpRequest Object

    Different browsers use different methods to create XMLHttpRequest object.

    Internet Explorer use an ActiveXObject.

    Other browsers uses a built in JavaScript object which is called as XMLHttpRequest.

    Here is the simplest code you can use to overcome this problem:

    var XMLHttp=null

    if (window.XMLHttpRequest)
    {
    XMLHttp=new XMLHttpRequest()
    }
    else if (window.ActiveXObject)
    {
    XMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
    }

    Above example is explained below:

    First create a variable XMLHttp to use your XMLHttpRequest object.Always set the value to null.

    Then test if the object window.XMLHttpRequest is available only. This object is available in newer versions of browser like Firefox, Mozilla, and Opera.

    If it is available, use it to create a new object:

    XMLHttp=new XMLHttpRequest().

    If it's not available,  test if an object window.ActiveXObject is available. This object is available in Internet Explorer version 5.5 and later on also.

    If it's available, use it to create a new object:

    XMLHttp=new ActiveXObject().

    A new Example:

    Some programmer will prefer to use the newest and fastest version of the XMLHttpRequest object.

    The example below try to load Microsoft's the latest version "Msxml2.XMLHTTP", available in Internet Explorer 6, before it falls back to "Microsoft.XMLHTTP", available in Internet Explorer 5.5 and later.

    var XMLHttp=null

    try
    {
    XMLHttp=new ActiveXObject("Msxml2.XMLHTTP")
    }
    catch(e)
    {
    try
    {
    XMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
    }
    }

    if (XMLHttp==null)
    {
    XMLHttp=new XMLHttpRequest()
    }

    Above example is explained below:

    First create a variable XMLHttp to use your XMLHttpRequest object. Always set the value to null.

    Then try to create the object the Microsoft , available in Internet Explorer 6 and later:

    XMLHttp=new ActiveXObject("Msxml2.XMLHTTP")

    If this catches an error, try the older (Internet Explorer 5.5) :

    XMLHttp=new ActiveXObject("Microsoft.XMLHTTP")

    If  XMLHttp still has a null value, try to create an object the "standard" way:

    XMLHttp=new XMLHttpRequest()

    XMLHttpRequest Methods

    The open() method.

    The open() method sets up a request to the web server.

    The send() method.

    The send() method sends a request to the web server.

    The abort() method.

    The abort() method aborts the current web server request





    XMLHttpRequest readyState Property

    The readyState property defines the current state of the XMLHttpRequest object.

    The code runs a query against an XML file and returns the result as HTML format.

    State Description
    0 The request is not initialized
    1 The request has been set up
    2 The request has been sent
    3 The request is in process
    4 The request is completed

    readyState=0This stae is used, after you have created the XMLHttpRequest object, but before you have called the open() method.

    readyState=1 This state is used, after you have called the open() method, but before you have called send().

    readyState=2This state is used, after you have called send().

    readyState=3 This state is used,after the browser has established a communication with the server, but before the server has completed the response.

    readyState=4 This state is used,after the request has been completed, and the response data have been completely received from the server.

    Note: Different browsers treat as ready state differently. Don't expect all browsers to report all states eqally. Some will not report 1 and 0.

    For Your AJAX web applications you will actually only be interested state 4. That is when the request is completed and it is safe use the received data




    Share And Enjoy:These icons link to social bookmarking sites where readers can share and discover new web pages.
    • blinkbits
    • BlinkList
    • blogmarks
    • co.mments
    • connotea
    • del.icio.us
    • De.lirio.us
    • digg
    • Fark
    • feedmelinks
    • Furl
    • LinkaGoGo
    • Ma.gnolia
    • NewsVine
    • Netvouz
    • RawSugar
    • Reddit
    • scuttle
    • Shadows
    • Simpy
    • Smarking
    • Spurl
    • TailRank
    • Wists
    • YahooMyWeb


    Previous Next

    HTML Quizes
    HTML Quiz
    XHTML Quiz
    CSS Quiz
    TCP/IP Quiz
    XML Quizes
    XML Quiz
    XSL Quiz
    XSLT Quiz
    DTD Quiz
    Schema Quiz
    XForms Quiz
    XSL-FO Quiz
    XML DOM Quiz
    XLink Quiz
    XQuery Quiz
    XPath Quiz
    XPointer Quiz
    RDF Quiz
    SOAP Quiz
    WSDL Quiz
    RSS Quiz
    WAP Quiz
    Web Services Quiz
    Browser Scripting Quizes
    JavaScript Quiz
    VBScript Quiz
    AJAX Quiz
    DHTML Quiz
    HTML DOM Quiz
    WMLScript Quiz
    E4X Quiz
    Server Scripting Quizes
    ASP Quiz
    PHP Quiz
    PERL Quiz
    SQL Quiz
    ADO Quiz
    .NET (dotnet) Quizes
    Microsoft.Net Quiz
    XML Web Services Quiz
    ASP.Net Quiz
    .Net Mobile Quiz
    C# : C Sharp Quiz
    ADO.NET Quiz
    VB.NET Quiz
    Multimedia Quizes
    SVG Quiz
    Flash Quiz
    Media Quiz
    SMIL Quiz
    Web Building  Quizes
    Web Browsers Quiz
    Web Hosting Quiz
    W3C Quiz
    Web Building Quiz
    Web Quality Quiz
    Web Semantic Quiz
    Web Careers Quiz
    Java Quizes
    Java Quiz
    JSP Quiz
    Servlets Quiz
    Struts Quiz
    EJB Quiz
    JMS Quiz
    JMX Quiz
    Programming Langauges Quizes
    C Quiz
    C++ Quiz
    Visual Basic Quiz
    Data Structures Using C Quiz
    Soft Skills Quizes
    Communication Skills Quiz
    Time Management Quiz
    Project Management Quiz
    Team Work Quiz
    Leadership Skills Quiz
    Corporate Communication Quiz
    Negotiation Skills Quiz

    Privacy Policy
    Copyright © 2003-2008 Vyom Technosoft Pvt. Ltd., All Rights Reserved.