Ajax invokes a simple instance _ajax related

Source: Internet
Author: User
Tags cdata

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.