Hello, I have an arduino uno, ethernet shield with SD so, my goal is to make this:
from an external HTML file (on a xampp server, for example) send a POST to arduino, arduino reads the post and send an answer to the HTML for example a string, at this point the HTML shows the answer in a div
so I am using HTML, JavaScript( jQuery library )
my arduino has the ip on lan 192.168.1.177
my xampp server has the ip on lan 192.168.1.195
so, I has wrote this code
file.html
<!DOCTYPE html>
<html>
<head>
<script src="jquery-1.7.1.js"></script>
<script>
function invia() {
$.ajax({
type: "POST",
data: "pinD3",
dataType: "text/html",
cache: false,
url: "http://192.168.1.177/",
success: function( r ){
$( "#result" ).html( r );
},
error: function(){$( "#result" ).html("error");}
});
};
</script>
</head>
<body>
<input id="test" onclick="invia()" type="button" value="Invia"/>
<div id="result"></div>
</body>
</html>
arduino sketch (in this sketch I'm sending a answer to HTML file only, nothing else)
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,1, 177);
EthernetServer server(80);
void setup()
{
Ethernet.begin(mac, ip);
server.begin();
}
void loop()
{
// listen for incoming clients
EthernetClient client = server.available();
if (client) {
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
//client.println();
client.println("answer");
client.println();
// give the web browser time to receive the data
delay(1);
// close the connection:
//client.flush();
client.stop();
}
}
and here is the problem, when I press the button "Invia" these one is writing into the result div "error", with other tests I have read the POST into the arduino and make a digitalPin LOW or HIGH, so the POST arrive at arduino but the answer don't arrive to the html file
If anyone can help me please, it's a project for an exam, thaks =(