IE& Ajax / XPath [英] IE & Ajax / XPath

查看:88
本文介绍了IE& Ajax / XPath的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读了无数的线程并试图实施许多不同的建议,但没有任何运气。

I've read countless threads and tried implementing many different suggestions, but haven't had any luck.

首先:

function ajaxRequest() {
        try {
                var request = new XMLHttpRequest();
        }
        catch(e1) {
                try {
                        var request = new ActiveXObject("Msxml2.HTMLHTTP");
                }
                catch(e2) {
                        try {
                                var request = new ActiveXObject("Microsoft.XMLHTTP");
                        }
                        catch(e3) {
                                var request = false;
                        }
                }
        }
        return request;
}

看起来IE成功使用XMLHttpRequest。据我所知,它正在加载XML,但Xpath是另一个故事:

It looks like IE is successfully using XMLHttpRequest. As far as I can tell, it's loading the XML fine, but Xpath is another story:

function XMLPath(doc, path) {
    try {
            return doc.evaluate(path, doc, null, XPathResult.STRING_TYPE, null).stringValue;
    } catch (e) {
            try {
                    doc.setProperty("SelectionLanguage", "XPath");
                    return doc.selectNodes(path);
            }
            catch(e2) {
                    alert(e2);
            }
    }

}

基本上,我必须在catch语句中更改哪些内容才能使其与IE一起使用?有趣的是它从不警告e2错误,这意味着它实际上并没有引发错误。完全混淆。

Basically, what must I change in my catch statement to make it work with IE? What's also interesting is that it never alerts an e2 error, meaning it's not actually throwing an error. Totally confused.

谢谢。

推荐答案

试试为IE返回doc.selectSingleNode(path).text; ,这是您访问路径找到的节点的字符串值时最接近的。

Try return doc.selectSingleNode(path).text; for IE, that is the closest you can get for accessing the string value of the node found by your path.

这篇关于IE& Ajax / XPath的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆