Click to Rate and Give Feedback
MSDN
MSDN Library
Web Development
HTML and CSS
Objects
 XMLHttpRequest Object
XMLHttpRequest Object

Represents an XML request via HTTP.

Members Table

The following table lists the members exposed by the XMLHttpRequest object.

Attributes/Properties
Show:
PropertyDescription
constructor New for Windows Internet Explorer 8  Returns a references to the constructor of an object.
onreadystatechange Sets or retrieves the event handler for asynchronous requests.
readyState Retrieves the current state of the request operation.
responseBody Retrieves the response body as an array of unsigned bytes.
responseText Retrieves the response body as a string.
responseXML Retrieves the response body as an XML Document Object Model (DOM) object.
status Retrieves the HTTP status code of the request.
statusText Retrieves the friendly HTTP status of the request.
timeout New for Internet Explorer 8  Gets or sets the time-out value.
EventDescription
ontimeout New for Internet Explorer 8  Raised when there is an error that prevents the completion of the request.
MethodDescription
abort Cancels the current HTTP request.
getAllResponseHeaders Returns the complete list of response headers.
getResponseHeader Returns the specified response header.
open Assigns method, destination URL, and other optional attributes of a pending request.
send Sends an HTTP request to the server and receives a response.
setRequestHeader Adds custom HTTP headers to the request.

Remarks

The XMLHttpRequest property is available on the window object in Internet Explorer 7.

var oReq = new XMLHttpRequest;

With the XMLHttpRequest object, Internet Explorer clients can retrieve and submit XML data directly to a Web server without reloading the page. To convert XML data into renderable HTML content, use the client-side XML DOM or Extensible Stylesheet Language Transformations (XSLT) to compose HTML elements for presentation.

The native scripting object also supports the use of expandos (custom properties), and properly recognizes the 'this' notation of Javascript.

For clients prior to Internet Explorer 7, use the following syntax to create the object:

var oReq = new ActiveXObject("MSXML2.XMLHTTP.3.0");

Example

The following script demonstrates how to create and use the XMLHttpRequest object:

if (window.XMLHttpRequest)
{
   var oReq = new XMLHttpRequest();
   oReq.open("GET", "http://localhost/test.xml");
   oReq.send();
   alert(oReq.statusText);
}

Standards Information

This object is defined in The XMLHttpRequest Object (W3C Working Draft) World Wide Web link.

Tags What's this?: ajax (x) Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Ajax -- Onreadystatechange method is not called      Bhoomi ... Stanley Roark   |   Edit   |  
Hi:

I am facing a problem in ajax.

My code functionality is retrieving data from database. For it i am using ajax.

i am including the code below which contains ajax function:

<script>
var req;
var which;

function fetchCorpClassTaxonomy(url) {
alert("entered into Ajax function");
if (window.XMLHttpRequest) { // Non-IE browsers
alert("NON IE Block is Invoked");
req = new XMLHttpRequest();
req.onreadystatechange = processStateChange;
try {
req.open("GET", url, true);
} catch (e) {
alert(e);
}
req.send(null);

} else if (window.ActiveXObject) { // IE
alert("entered into IE block");
req = new ActiveXObject("Microsoft.XMLHTTP");
if (req) {
alert("entered into if(req)");
req.onreadystatechange = processStateChange;
req.open("GET", url, true);
alert("readystate: "+ req.readyState);
req.send();
}
}
}

function processStateChange() {
alert("entered into processStateChange()");
if (req.readyState == 4) { // Complete
if (req.status == 200) { // OK response
alert("response received from server is "+req.responseText);
var serverResponse = req.responseText;
var fieldName = serverResponse.substring(0,serverResponse.indexOf ("|"));
//alert("fieldname string "+fieldName);
var restResponse = serverResponse.substring(serverResponse.indexOf ("|")+1,serverResponse.length);
//alert("rest of Response is "+restResponse);
if(fieldName == "classification"){
document.getElementById("subclassification").innerHTML = restResponse;
}
} else {
alert("Problem: " + req.statusText);
}
}
}
</script>

I am getting response from action class so there is no problem in my other code.

when fetchCorpClassTaxonomy(url) function is called it is going to IE block since i am using IE 7.0

After that
alert("readystate: "+ req.readyState);
is also coming.

but the function processStateChange() is not called.
The alert just inside the function :

alert("entered into processStateChange()"); is also not executing.


The problem is function processStateChange() is not called.


Please give me your valuable suggestions As Soon As Possible for solving the problem. Since i am new to Ajax I am not able to find the solution.

Thanks.....

Tags What's this?: ajax (x) Add a tag
Flag as ContentBug
Ajax - Open method resets all properties of Request object      John Sudds - MSFT   |   Edit   |  

Calling the open method initializes the request object. If you have set properties (such as onreadystatechange) it is reset to initial default values (NULL). So, do all your initialization between OPEN and the final call to SEND.

Tags What's this?: ajax (x) Add a tag
Flag as ContentBug
NTLM Authentication & Load Balancing      Tom At Moto   |   Edit   |  
It seems that there's also an issue with load balancing (using the IIS load balancer) and NTLM authentication on IE. Basically, you either get prompted to log in, or nothing happens at all (and an error is thrown: "The download of the specified resource has failed."

I've also seen this happen when using AJAX resources through a router or firewall that requires NTLM authentication.
Tags What's this?: Add a tag
Flag as ContentBug
Processing
© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker