热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

使用E4X通过Ajax返回进程XML?-ProcessXMLreturnedviaAjaxwithE4X?

IamloadingsomeXMLviaAjax.我通过Ajax加载一些XML。hereisasnippetofthescript:这是脚本的片段:ajaxRequ

I am loading some XML via Ajax.

我通过Ajax加载一些XML。

here is a snippet of the script:

这是脚本的片段:

ajaxRequest.Onreadystatechange= function()
    {
        if(ajaxRequest.readyState == 4)
        {
            document.getElementById('loading').innerHTML = 'done';
            google_xml = ajaxRequest.responseXML;
            document.getElementById('xml').innerHTML = 'XML: '+google_xml.toXMLString();
        }
    }

The page I am loading is an XML file, the file loads because if I alert(ajaxRequest.responseText); I see it. But I am not sure how to process it as XML I thought the above script would put the XML as a string into the

element but it doesnt.

我加载的页面是一个XML文件,文件加载因为我提醒(ajaxRequest.responseText);我看到了。但我不知道如何将其作为XML处理我认为上面的脚本会将XML作为字符串放入

元素中,但它并不存在。

I have used E4X to process XML a lot in Actionscript but never in JS, can someone give me a hint? Thanks!

我已经使用E4X在Actionscript中处理了很多XML但从来没有在JS中,有人能给我一个提示吗?谢谢!

3 个解决方案

#1


I'm not sure what browser you are using but Firefox is currently the only browser with good support for E4X.

我不确定你使用的是哪种浏览器,但Firefox是目前唯一一款能够很好地支持E4X的浏览器。

Though, to expand on this answer, you may want to be aware of the alternative:

但是,为了扩展这个答案,您可能想要了解替代方案:

There's plenty of support for parsing XML in the browser, just not with E4X. You may want to use the jQuery and use dataType:XML. See xml.com/pub/a/

在浏览器中解析XML有很多支持,而不是E4X。您可能希望使用jQuery并使用dataType:XML。见xml.com/pub/a/

#2


For those who follow after with this same question:

对于那些追随同样问题的人:

var x = new XML('string value');

var x = new XML(' string value ');

...now your x value is an xml object that you can manipulate with E4X!

...现在你的x值是一个可以用E4X操作的xml对象!

#3


Just use xhr.responseXML which is already an XML object with DOM support after the request is fullfilled. If the browser supports the XmlHttpRequest object, this should work directly. Also, IIRC, you can use jQuery to wrap the object and use it's own find/each methods for traversing the object.

在请求完成后,只需使用xhr.responseXML,它已经是一个支持DOM的XML对象。如果浏览器支持XmlHttpRequest对象,则应该直接使用。另外,IIRC,您可以使用jQuery来包装对象并使用它自己的find / each方法来遍历对象。


推荐阅读
author-avatar
ytm5295526049760
这个家伙很懒,什么也没留下!
Tags | 热门标签
RankList | 热门文章
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有