How to create the XMLHttpRequest Object?
I have done some basic things with a XML (Extensible Markup Language). Now I want to communicate with the server from inside a web page. I came to know that using XMLHttpRequest Object will help me to communicate with the server. But, I don't know how to create the XMLHttpRequest Object?:crybaby: Also I am having doubt that using the XMLHttpRequest Object, does it update a web page with new data without reloading the page..?? Please help me to solve my problem.
Re: How to create the XMLHttpRequest Object?
You can use the XMLHttpRequest Object for communicating with your server from inside a web page. Also after using a XMLHttpRequest Object, the web page with new data gets updated without reloading the page. I am sure that your doubt will be cleared about the updating the web page..!! Also by using this object, it requests and receive new data from a server after the page has loaded. You can also communicate with a server in the background by creating a XMLHttpRequest Object. Hope that you have got some useful information from this reply..!!:whistling
Re: How to create the XMLHttpRequest Object?
If you want to submit form data or load data from a server then you can use the XMLHttpRequest object. The XMLHttpRequest object implements an interface exposed by a scripting engine that allows scripts to perform HTTP client functionality. An XMLHttpRequest object supports any text based format, including XML. If you want to make requests over both HTTP, you can use this object. You can understand bit more after looking the following example :
Code:
function test(data)
{
}
function handler() {
if(this.readyState == 4 && this.status == 300) {
if(this.responseXML != null && this.responseXML.getElementById('test').firstChild.data)
test(this.responseXML.getElementById('test').firstChild.data);
else
test(null);
} else if (this.readyState == 4 && this.status != 300) {
test(null);
}
}
var client = new XMLHttpRequest();
client.onreadystatechange = handler;
client.open("GET", "test.xml");
client.send();
Re: How to create the XMLHttpRequest Object?
You can create an XMLHttpRequest object, just by writing a single line of JavaScript. If you are working on older browsers (like Internet Explorer 5 and 6), then use the following code :
Code:
var xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
And if you are using modern browsers than you can use :
Code:
var xmlhttp=new XMLHttpRequest()
Re: How to create the XMLHttpRequest Object?
This is little bit tough to understand, but you will have to take a look to clear your concepts about the XMLHttpRequest Object. Each XMLHttpRequest object has an associated XMLHttpRequest origin and an XMLHttpRequest base URL. The specification defines their values when the global object is represented by the Window object. When the XMLHttpRequest object used in other contexts their values will have to be defined as appropriate for that context. Also the user agent must return a new XMLHttpRequest object when the XMLHttpRequest() constructor is invoked.
Re: How to create the XMLHttpRequest Object?
The onreadystatechange is an event handler attribute which has to handle event type readystatechange by the XMLHttpRequest object.The XMLHttpRequest object can be in several states. The readyState attribute, on getting, must return the current state, which must be one of the following values :
- UNSENT (numeric value 0) means that the object has been constructed.
- OPENED (numeric value 1) refers that open() method has been successfully invoked.
- HEADERS_RECEIVED (numeric value 2) comes when all HTTP headers have been received.
- LOADING (numeric value 3) means that the entity body is being received.
- DONE (numeric value 4) This value comes when the data transfer has been completed. It also comes when something is wrong in transfer of data.