[xmlhttprequest] probleme avec open
y a-t-il des contraintes sur l'utilisation de XmlHttpRequest ?
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 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
| <html>
<head>
<script language="javascript">
function start() {
var url = document.getElementById("url").text;
return send(url,"","GET");
}
function send(url,data,method) {
var xhr = null;
if (window.XMLHttpRequest) {
xhr = new XMLHttpRequest();
} else {
alert ("xmlhttprequest non supporte");
xhr = false;
}
xhr.onreadystatechange = function() {
// On ne fait quelque chose que si on a tout revu et que le serveur est ok
if ((xhr.readyState == 4) && (xhr.status == 200)) {
alert(xhr.responseText);
return xhr.responseText;
}
}
alert ("xhr cree "+xhr);
if (method == "POST") {
xhr.open("POST",url,true);
xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhr.send(data);
} else {
if (data == "") {
xhr.open("GET",url,true);
} else {
xhr.open("GET",url+'?'+data,true);
}
xhr.send(null);
}
}
</script>
</head>
<body>
<input id="url" type="text" />
<br/><br/>
<div id="page"></div>
<br/><br/>
<a href="javascript:start()">commencer</a>
</body>
</html> |
et ça m'envoie l'erreur suivante :
Code:
uncaught exception: [Exception... "Component returned failure code: 0x80070057 (NS_ERROR_ILLEGAL_VALUE) [nsIXMLHttpRequest.open]" nsresult: "0x80070057 (NS_ERROR_ILLEGAL_VALUE)" location: "JS frame :: file:///home/gorgonite/ensta/ppl/js/test.html :: anonymous :: line 0" data: no]
Edit: j'ai mis l'url http://www.google.fr