Thursday 23 June 2011 3:07:57 am
Hello, I'm trying to use the REST api in order to retreive some content with ajax. When I try the url http://my_host/api/ezp/v1/content/node/2 on my browser (chorme or firefox), I get the informations but not with a xmlHttpRequest. Here is my HTML code : <html>
<head>
<script language="JavaScript">
function submitForm()
{
var xhr=null;
try
{
xhr = new XMLHttpRequest();
} catch(e)
}
xhr.onreadystatechange = function()
{
dyn = document.getElementById('dyn');
dyn.innerHTML="Wait server...";
if(xhr.readyState == 4)
{
if(xhr.status == 200)
{
dyn.innerHTML="Received:" + xhr.responseText;
}
else
{
dyn.innerHTML="Error: returned status code " +
xhr.status + " " + xhr.statusText+" Response : "+ xhr.responseXml;
}
}
};
xhr.open("GET", "http://<a href="http://my_host/api/ezp/v1/content/node/2">my_host/api/ezp/v1/content/node/2</a>", true);
xhr.send(null);
}
</script>
</head>
<body>
<input type="submit" value="Submit" onclick="submitForm()" />
<textarea type="text" id="dyn" value=""></textarea>
</body>
</html>
The status of the xhr is always 0 and the responsetext is empty. Any clue ?
|