AJAX

AJAX - XMLHttpRequest Object

The XMLHttpRequest object is an API that is used to transferring data between a web browser and a web server using HTTP protocol and also provides the connection between a client and server.

The object is provided by the browsers scripting languages looks like JavaScript, JScript, and other environments.

It is also known as short name “XHR”.

The concept behind the XMLHttpRequest object was originally created by Microsoft.

The XMLHttpRequest property looks like,

a)      onreadystatechange
b)     responseText
c)      responseXML
d)     status
e)      statusText
f)       readyState : the readyState can be 0, 1, 2, 3 and 4.
                                            i.            0-Your request is not initialized.
                                          ii.            1-Your request has been set up.
                                        iii.            2-Your request has been sent.
                                        iv.            3-Your request is in process.
                                          v.            4-Your request is completed.

The XMLHttpRequest method looks like,

a)      abort()
b)     setRequestHeader(label, value)
c)      getAllResponseHeaders()
d)     getResponseHeader(mame)
e)      open(method, URL, async, userName, password)
f)       send(content)

The XMLHttpRequest object Syntax looks like,
//Syntax - XMLHttpRequest Object.
var xhrp = new XMLHttpRequest();
Example,
//AJAX - The Event onreadystatechange.
var loadXhr = function() {
    var xhrp = new XMLHttpRequest();
    xhrp.onreadystatechange = function() {
        if (this.readyState == 4 && this.status == 200) {
            document.getElementById("yourElementId").innerHTML = this.responseText;
        }
    };

    xhrp.open("GET", "ajax-info-text.txt", true);
    xhrp.send();
}
ANIL SINGH

Hey! I'm Anil Singh. I author this blog. I'm Active Blogger, Programmer. I love learning new technologies, programming, blogging and participating the forum discussions more...
My Blogs - http://www.code-sample.com and http://www.code-sample.xyz
My Books - Google Amazon and Flipkart Book Store!

You Might Also Like
Post a Comment
www.code-sample.com/. Powered by Blogger.
ASK Questions
SQL Server NodeJs TypeScript JavaScript Angular SQL Server My Book