IE & Ajax / XPath

I read countless streams and tried to implement many different sentences, but had no 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 loads XML perfectly, 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 should I change in my catch statement to make it work with IE? What is also interesting is that it never warns about an e2 error, which means that it is actually not an error. Totally embarrassed.

Thanks.

0
source share
1 answer

Try return doc.selectSingleNode(path).text; for IE, this is the closest you can get to access the string value of the node found in your path.

+1
source

Source: https://habr.com/ru/post/1384610/


All Articles