The original intention of Ajax is to allow people to obtain XML content asynchronously to achieve a web page effect without refreshing.
asp.net ajax has implemented the underlying content encapsulation, which is far more convenient than writing xmlhttp. At least it is much better in terms of browser compatibility. Let's use an example of www.asp.net to illustrate the use of microsoft ajax library to simply asynchronously obtain xml documents. method
//Return XML Web request
function OnSucceededXml(executor, eventArgs)
...{
if (executor.get_responseAvailable())
...{
if(document.all)
resultElementId.innerText += executor.get_xml().xml;
else
// Firefox
resultElementId.textContent += "First node[first node]: " +
executor.get_xml().documentElement.nodeName;
}
else
...{
if (executor.get_timedOut())
alert("timeout");
else
if (executor.get_aborted())
alert("failure");
}
}
function GetXml()
...{
//Create WebRequest object
wRequest = new Sys.Net.WebRequest();
//Set the request file
wRequest.set_url("index.xml");
// Set the request handler.
wRequest.add_completed(OnSucceededXml);
// Clear the results area.
if(document.all)
resultElementId.innerText = "";
else
// Firefox
resultElementId.textContent = "";
//Invoke the Web request.
wRequest.invoke();
}
<button id="Button3"
onclick="GetXml()">Xml</button>
<div id="ResultId" style="background-color:Aqua;"></div>