Non so se è questo ...onSubmit="java-script:sndReq(this);"Originariamente inviato da chiamatekatia
Ciao a tutti
E' la prima volta che cerco di usare AJAX e avendo ben poche basi di javascript potrei avere commesso un errore assolutamente di base ^^''
Il problema, sinteticamente, è che il codice (che dovrebbe inviare delle variabili da javascript e php) non funziona...
La pagina login_informazioni.php è fatta invece così:codice:<html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Documento senza titolo</title> <script type="text/javascript"> function createRequestObject() { var ro; var browser = navigator.appName; if(browser == "Microsoft Internet Explorer"){ ro = new ActiveXObject("Microsoft.XMLHTTP"); }else{ ro = new XMLHttpRequest(); } return ro; } var http = createRequestObject(); function sndReq() { var username = document.form1.username.value; var password = document.form1.password.value; //controllo che il modulo sia pieno if (username != "" & password != "") { var altezza = window.screen.height; var larghezza = window.screen.width; var risoluzione = larghezza+'X'+altezza; var browser = navigator.appName; var sistema = navigator.userAgent; var indirizzo = 'login_informazioni.php?browser='+browser+'&risoluzione='+risoluzione+'&sistema='+sistema+'&username='+username+'&password='+password; http.open('get', indirizzo); http.onreadystatechange = handleResponse; http.send(null); } } function handleResponse() { if(http.readyState == 4){ var response = http.responseText; //0 tutto ok, 1 errore if(response == 0) { alert (response); } else { alert ("E' incorso un errore."); } } } </script> </head> <body> <form id="form1" name="form1" method="post" action="login2.php" onSubmit="javascript:sndReq(this);" > <table width="100%" border="0"> <tr> <td width="50%">Username:</td> <td width="50%"><label> <input name="username" type="text" id="username" /> </label></td> </tr> <tr> <td width="50%">Password:</td> <td width="50%"><input name="password" type="password" id="password" /></td> </tr> </table> <p align="center"> <label> <input type="submit" name="Submit" value="Invia"/> </label> <label> <input type="reset" name="Submit2" value="Ripristina" /> </label> </p> </form> </body> </html>
Come alert alla fine mi risulta che response è una variabile vuota. Inoltre neanche le informazioni (browser, risoluzione, etc.) vengono inserite nel database (ma la pagina php non ha errori, ho controllato)Codice PHP:
<?
include("connetti.php");
$username = $_REQUEST['username'];
$password = $_REQUEST['password'];
$browser = $_REQUEST['browser'];
$sistema = $_REQUEST['sistema'];
$risoluzione = $_REQUEST['risoluzione'];
$ip = getenv("REMOTE_ADDR");
$errore = 0;
[inserisce queste informazioni nel database]
echo "$errore";
?>
mettilo cosi ...onSubmit="return sndReq(this);"