1

I'm new to HTTP and JS so please bear with me.

I'm trying to get JSONP working with an Arduino Ethernet shield. But before going that far I wanted to confirm the basic functionality. The Arduino is running a web server. I make it send a simple text reply.

// listen for incoming clients
EthernetClient client = server.available();
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
client.print("Test Text");

The Arduino code is just for reference. It's not important.

When I just point the browser to the Arduino IP I can successfully see the "Test Text" in the browser. So I know that it is working and responding properly.

Now this is my JS code:

window.onload = init;

function init()
{
    SendRequest();
}

function SendRequest()
{
    alert("Sending request");
    var url = "http://192.168.1.177";
    var request = new XMLHttpRequest();
    request.open("GET", url);
    request.onload = arduinoCallback;
    request.send(null);
}


function arduinoCallback()
{
    alert("Callback received!!!");
}

I debugged with Chrome dev tools and put a breakpoint in arduinoCallback but it is never called.

Could somebody please help with this. I can see in the Arduino server that it receives the connection and sends back the reply, same as it would if I just type in the server IP.

Thank you.

madu
  • 5,232
  • 14
  • 56
  • 96
  • 1
    Do you see anything in the Network tab? There was a similar question about Firefox: http://stackoverflow.com/questions/14727710/xmlhttprequest-onload-not-called – Barmar May 05 '13 at 16:34
  • @Barmar Thank you. I put the callback function to onreadystatechange and it works. I can't understand why it would call on onreadystatechanged and not onload. – madu May 05 '13 at 16:47

0 Answers0