Simple ajax call example,
This document describes how to call ajax. We will share this with you for your reference. The details are as follows:
Enter the data returned by the url in the div of the specified id.
Client: test.html
<Script> function createXMLHttp () {var ret = null; try {ret = new ActiveXObject ('msxml2. XMLHTTP ');} catch (e) {try {ret = new ActiveXObject ('Microsoft. XMLHTTP ');} 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 = ' loading data... <br/> '; var xmlhttp = createXMLHttp (); xmlhttp. open ("GET", fragment_url); xmlhttp. onreadystatechange = function () {if (xmlhttp. readyState = 4 & xmlhttp. status = 200) {// alert (Xmlhttp. 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>
Enter the data returned by the url in the div of the specified id.
Server:
Test. xml
<?xml version='1.0' encoding='utf-8' ?><data><![CDATA[ this is a test]]></data>
Note that the server returns data in CDATA format, which can contain any html code.
I hope this article will help you with ajax programming.
Articles you may be interested in:
- Analysis of data passing parameters in ajax
- Case study of Ajax asynchronous data submission return value line feed
- An analysis of differences between IE and FF on the differences between parameters passed by Ajax in Chinese
- Example Analysis of passing parameters in Javascript Based on AJAX callback function
- Simple Ajax call instance implemented by jQuery + json
- Analysis of Ajax () data parameter type instances in JQuery