Simple ajax call example,

Source: Internet
Author: User

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

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.