[AJAX] Consommer un web service
Bonjour,
Je veux consommer un web service REST/XML via javascript. Cela fonctionne bien avec IE mais pas avec Firefox. Je tourne en rond, qq un aurait il une idee ?
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
function getXhr() {
var xhr = null;
if (window.XMLHttpRequest)
xhr = new XMLHttpRequest();
else if (window.ActiveXObject) {
try {
xhr = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
xhr = new ActiveXObject("Microsoft.XMLHTTP");
}
}
else {
alert("Your browser does not support XMLHTTPRequest (Ajax method)...");
xhr = false;
}
return xhr
} |
Ca plante au niveau ResponseXML avec FF
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
|
function test(url) {
var xhr = getXhr();
if (xhr) {
xhr.open("GET", url, true);
xhr.setRequestHeader("Content-type", "text/xml; charset=utf-8");
xhr.send(null);
xml = xhr.responseXML.xml;
//xml = xhr.responseText;
alert(xml);
}
var xml_doc = new ActiveXObject("Microsoft.XMLDOM");
xml_doc.async = false;
xml_doc.loadXML(xml);
//xml_doc.childNodes[0].childNodes
nodeList = xml_doc.getElementsByTagName("Clients");
alert(nodeList.length);
document.getElementById("test").innerHTML = "";
document.getElementById("TextAreaGET").innerHTML = "";
for (var i = 0; i < nodeList.length; i++) {
document.getElementById("test").innerHTML += nodeList[i].getElementsByTagName("ClientShortName")[0].text + "<br>";
}
} |
Merci à vous