Get the App
SLTechnology News&Howtos  ›  Development  › 

How to create a XML HttpRequest object

Shulou Source: shulou.com Published: 2022-06-03 19:54:01 10月27日 Update

This article focuses on "how to create XML HttpRequest objects", interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to create a XML HttpRequest object.

Utl.js

The code is as follows:

Function createXmlTree (node, indent) {

If (node = = null)

Return ""

Var str = ""

Switch (node.nodeType) {

Case 1: / / Element

Str + = ""

Str + = ">"

Var cs = node.childNodes

For (var I = 0; I

< cs.length; i++) str += createXmlTree(cs[i], indent + 3); str += ""; break; case 9: // Document var cs = node.childNodes; for (var i = 0; i < cs.length; i++) str += createXmlTree(cs[i], indent); break; case 3: // Text if (!/^\s*$/.test(node.nodeValue)) str += "" + node.nodeValue + ""; break; case 7: // ProcessInstruction str += "" break; case 4: // CDATA str = "" + node.nodeValue + "]" + "]>

"

Break

Case 8: / / Comment

Str = ""

Break

Case 10:

Str = ""

/ / TODO: Handle custom DOCTYPE declarations (ELEMENT, ATTRIBUTE, ENTITY)

Break

Default:

/ / alert (node.nodeType + "\ n" + node.nodeValue)

Inspect (node)

}

Return str

}

Function inspect (obj) {

Var str = ""

For (var k in obj)

Str + = "obj." + k + "=" + obj [k] + "\ n"

Window.alert (str)

}

Function createXmlAttribute (a) {

Return "" + a.nodeName + "=\"+ a.nodeValue +"\ ""

}

The code is as follows:

Ajax test

/ /-XMLHttpObj class-

Function XMLHttpObject (url,Syne) {

Var XMLHttp=null

Var o=this

This.url=url

This.Syne=Syne

This.sendData = function ()

{

If (window.XMLHttpRequest) {

XMLHttp = new XMLHttpRequest ()

} else if (window.ActiveXObject) {

XMLHttp = new ActiveXObject ("Microsoft.XMLHTTP")

}

With (XMLHttp) {

Open ("GET", this.url, this.Syne)

Onreadystatechange = o.CallBack

Send (null)

}

}

This.CallBack=function ()

{

If (XMLHttp.readyState = = 4) {

If (XMLHttp.status = = 200) {

O.debugXML ("readyState:" + XMLHttp.readyState + "")

O.debugXML ("status:" + XMLHttp.status + "")

O.debugXML ("" + createXmlTree (XMLHttp.responseXML,0) + "")

}

}

}

This.getText=function ()

{

If (XMLHttp==null) {return "not loaded XMLHttpRequest"}

If (XMLHttp.readyState==4) {return XMLHttp.responseText}

Return XMLHttp.readyState

}

This.debugXML=function (log)

{

Try {document.getElementById ("XMLDebug") [xss_clean] + = log}

Catch (e) {}

}

}

Var XMLDoc1=new XMLHttpObject ("tree.xml", true)

Tree.xml xtree.xsl Blog

Feed

Tags: Objects code content learning practical deeper interested practical practical easy to operate methods more friends websites channels queries Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux OPPO Reno MariaDB Docker Microsoft