Get the App
SLTechnology News&Howtos  ›  Development  › 

How does ajax implement calling

Shulou Source: shulou.com Published: 2022-06-03 19:32:31 11月12日 Update

This article is to share with you about how ajax implements calls. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

The details are as follows:

Populate the data returned by url into the div of the specified id

Client: test.html

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 [XSS _ clean] ='

Data loading.'; 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 [XSS _ clean] = unescape (xmlhttp.responseXML.getElementsByTagName ("data") [0] .childNodes [0] .nodeValue) If (! element [XSS _ clean] | | Element [XSS _ clean] = "/ n") {try {Element [XSS _ clean] = unescape (xmlhttp.responseXML.firstChild.childNodes [1] .nodeValue);} catch (e) {}} xmlhttp.send (null);} var url= "t.xml"; / / alert (url); loadXmlToElement (url, "data")

Populate the data returned by url into the div of the specified id

Server:

Test.xml

Note that the server returns data in CDATA format, which can be any html code internally

Thank you for reading! This is the end of the article on "how to call ajax". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it out for more people to see!

Tags: Data content more articles services good practical code client client article server format look knowledge reference help related Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL vpn Microsoft MariaDB Shulou Information