I want to access to the service web via my PhoneGap/android application with xmlhttprequest, but the code below returns “Status is 401”.
var request = new XMLHttpRequest();
request.open("GET","http://www.mysite.fr/api/customers/2",true);
request.onreadystatechange = function() {
alert("Status is "+request.status);
if (request.status == 200 || request.status == 0){
response = request.responseXML.documentElement;
itemDescription = response.getElementsByTagName('lastname')[0].firstChild.data;
alert ( itemDescription );
}
}
request.send();
Can anyone help me explaining the error or offering me a solution?
if your website is created by prestashop, so to access the webservice using Xmlhttprequest, the request.open should be like this:
with:
PHP_AUTH_USER="" and ws_ke=key_generated_by_the_webservice