IE & Ajax / XPath

六眼飞鱼酱① 提交于 2019-12-13 03:55:51

问题


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

first:

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;
}

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);
            }
    }

}

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.

Thanks.


回答1:


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.



来源:https://stackoverflow.com/questions/6641853/ie-ajax-xpath

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!