Grazie per i suggerimenti. Sono arrivato alla seguente soluzione:
codice:
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-1.4.4.min.js"></script>
<script>
$(document).ready(function() {
$("#button1").show();
$("#button2").hide();
});
</script>
<script>
function invia(msg) {
jQuery.support.cors = true;
if(msg == "accendi"){
$.ajax({
crossDomain: true,
async : true,
type: "GET",
data: "pinD7",
dataType: "text/html",
cache: false,
url: "http://ledon.dlinkddns.com",
success: function( r ){
$( "#result" ).html("led acceso");//html( r );
$("#event").attr("src","ledon.png");
$("#button1").hide();
$("#button2").show();
},
error: function(){$( "#result" ).html("impossibile accendere il led");}
});
}
else{
$.ajax({
crossDomain: true,
async : true,
type: "GET",
data: "pinL7",
dataType: "text/html",
cache: false,
url: "http://ledon.dlinkddns.com",
success: function( r ){
$( "#result" ).html("led spento");//html( r );
$("#event").attr("src","ledoff.png");
$("#button1").show();
$("#button2").hide();
},
error: function(){$( "#result" ).html("impossibile spegnere il led");}
});
}
};
</script>
</head>
<body>
<center>
<input id="button1" onclick="invia('accendi')" type="button" value="Accendi led"/>
<input id="button2" onclick="invia('spegni')" type="button" value="Spegni led"/>
<div id="result">
</div>
<img id="event" src="ledoff.png" alt="Accendi" title="Accendi" width="25" height="25"/>
</center>
</body>
</html>
ma tale codice funziona parzialmente nel senso che: se clicco su "Accendi led", la richiesta get viene correttamente inviata e termina con success; se riclicco ( a questo punto sul pulsante "Spegni led" che appare dopo la prima richiesta), la richiesta va in errore:
GET http://ledon.dlinkddns.com/?_=1416407316546&pinL7 net::ERR_EMPTY_RESPONSE
Sapete a cosa è dovuto?