Some tips on recent studies of XMLHTTP

Source: Internet
Author: User
Tags add array return tagname xsl
Xml| experience recently studied a bit XMLHTTP, still very interesting dongdong. I like to let it in IE6 and Firefox are running normally, the background is dom4j to parse.

1. Download Http://webfx.eae.net/dhtml/xmlextras/xmlextras.zip package, there is a xmlextras.js, take it out, I used to generate XMLHTTP objects.

2. Add the following code to the Xmlextras.js:

Check Browsers

var ua = navigator.useragent;

var opera =/opera [56789]|opera\/[56789]/i.test (UA);

var ie =!opera &&/msie [56789]/i.test (UA);

Preventing opera to be identified as IE

var Mozilla =!opera &&/mozilla\/[56789]/i.test (UA);

Preventing opera to is identified as mz/* end Browser Checks * *
if (Mozilla) {

XMLDocument.prototype.selectSingleNode = function (tagname) {

var result = This.evaluate (tagname, this, NULL, 0, NULL);

return Result.iteratenext ();

}

XMLDocument.prototype.selectNodes = function (tagname) {

var result = This.evaluate (tagname, this, NULL, 0, NULL);

var xns = new XMLNodes (result);

return XNS;

}

Defines a new class to be compatible with the return type of selectnodes () in IE.

function XMLNodes (Result) {

this.length = 0;

This.pointer = 0;

This.array = new Array ();

var i = 0;

while ((This.array[i]=result.iteratenext ())!=null)

i++;

This.length = This.array.length;

}

XMLNodes.prototype.nextNode = function () {

this.pointer++;

return this.array[pointer-1];

}

XMLNodes.prototype.reset = function () {

This.pointer = 0;

}}

Let Firefox support some of the same interfaces as IE.

3.XmlHttp return, if you need to xmlhttp.responsexml objects, in Firefox everything is normal, but in the IE6 is not often, so need to new one XmlDocument:

var doc = Xmldocument.create ();

Doc.loadxml (Xmlhttp.responsetext);

4. Use XSL to translate XML, if you want to keep spaces, you need to add

Xml:space= "preserve", for example:

<xsl:for-each select= "parameter" xml:space= "preserve" >

5. Xmlhttp.open in Firefox ("POST", url, True); The last argument cannot be false, otherwise there will be an error.



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.