So I send somme ajax request to my arduino Yun and I get this :
XMLHttpRequest cannot load http://MyYun.local/arduino/avancer/200. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.
But the request is send because my motor turn... But I can't read the value of a pin... (I can with my browser directly or a simple REST client but not with a request)
So I try to send this unsuccessfully :
function avancer(){
var nombrePasAvancer = $("#NbPasAvancer").val();
$.ajax({
type: 'GET',
url: 'http://MyYun.local/arduino/avancer/' +nombrePasAvancer,
header:{'Access-Control-Allow-Origin': '*'},
})
}
I have succes with this code in -disablesecurity mode in chrome :
function distance(){
var requestObject = new XMLHttpRequest();
requestObject.open('GET', 'http://MyYun.local/arduino/distance/1');
requestObject.onreadystatechange = function() {
if(requestObject.readyState == 4)
{
var valeurCapteur = requestObject.responseText;
alert(valeurCapteur );
}
};
requestObject.send('toto=tutu&tata=titi');
But I want to export my code and use him everywhere and note only in this disablesecurity mode.
I think I just need to put somme headers access but I don't find how.
Thank you to help me with ajax request or XMLHttpRequest.
But I think I don't understand because google said with JSONP the HTTP request wait for a callback in JSONP or Arduino don't return JSONP but only some data...
So with this code :
function distance(){
$.ajax({
url: "http://MyYun.local/data/get/13",
dataType: "jsonp",
jsonp: 'jsonp',
}).done(function(response) {
console.log(response.key);
});
}
with this in the arduino:
client.println("Status: 200");
client.println("Content-type: text/javascript");
client.println("Access-Control-Allow-Origin: *");
// any other header
client.println(); //mandatory blank line
client.println(distance); //the response body
And it's work finally if this can help someone else !