The examples in this article describe the methods of Ajax invocation. Share to everyone for your reference, specific as follows:
Populates the div with the specified ID with the data returned by the URL
Client: test.html
<script> function Createxmlhttp () {var ret = null;
try {ret = new ActiveXObject (' msxml2.xmlhttp ');
catch (e) {try {ret = new ActiveXObject (' microsoft.xmlhttp ');
The catch (ee) {ret = null;
} if (!ret && typeof xmlhttprequest!= ' undefined ') ret = new XMLHttpRequest ();
return ret;
function Loadxmltoelement (Fragment_url, element_id) {var element = document.getElementById (element_id);
element.innerhtml = ' data loading ...<br/> ';
var xmlhttp = createxmlhttp ();
Xmlhttp.open ("Get", fragment_url); Xmlhttp.onreadystatechange = function () {if (xmlhttp.readystate = 4 && xmlhttp.status =) {//alert x
Mlhttp.responseXML.getElementsByTagName ("Data") [0].childnodes[0].nodevalue);
element.innerhtml = unescape (Xmlhttp.responseXML.getElementsByTagName ("Data") [0].childnodes[0].nodevalue); if (!element.innerhtml | | element.innerhtml = = "/n") {try{element.innerhtml = unescape (Xmlhttp.responsexml.firstchild.childnodes[1].nodevalue);
}catch (e) {}}}} xmlhttp.send (null);
} </script> <div id= "Data" > </div> <script> var url= "T.xml";
alert (URL);
Loadxmltoelement (URL, "data");
</script>
Populates the div with the specified ID with the data returned by the URL
Service side:
Test.xml
<?xml version= ' 1.0 ' encoding= ' utf-8 '?>
<data>
<![ cdata[This is
a test
]]>
</data>
Note The server returns the CDATA format data, which can be any HTML code inside
I hope this article will help you with Ajax programming.