ciao a tutti sn nuovo registrato . io sto facendo delle prove con ajax perchè è da poco che lo uso ho creato un semplice script con ajax del login ma quando faccio click sul pulsante login non ma da nessun messaggio non riesco capire cosa sbaglio qualche aiuto grazie mille
codice:
<div id="wrapper">
<div id="form">
<form action="response.php" method="post">
<label>Username</label>
<input type="text" name="logusername" id="logusername">
<lable>Password</lable>
<input type="password" name="logpassword" id="logpassword">
<input type="submit" name="logsubmit" id="logsubmit" value="LOGIN" onclick="getConnectionResponse();return false;">
</form>
<div id="feedback"></div>
</div>
</div>
codice:
function getXML_HTTP(){
var xmlHTTP = null;
if(window.XMLHttpRequest){
xmlHTTP = new XMLHttpRequest();
}else if(window.ActiveXObject){
xmlHTTP = new ActiveXObject("Microsoft.XMLHTTP");
}
return xmlHTTP;
}
function getConnectionResponse(){
var xmlhttpRequestFunc = getXML_HTTP();
var pageURL = "response.php";
var logusername = document.getElementById("logusername").value;
var logpassword = document.getElementById("logpassword").value;
var logdata = 'logusername='+logusername+'&logpassword='+logpassword;
xmlhttpRequestFunc.open("POST", pageURL ,true);
xmlhttpRequestFunc.setRequestHeader("Content-type","x-www-form-urlencoded");
xmlhttpRequestFunc.send(logdata);
xmlhttpRequestFunc.onreadystatechange = function(){
if(xmlhttpRequestFunc.readyState == 4){
if(xmlhttpRequestFunc.readyState == 200){
var htmlElement = document.getElementById("feedback");
htmlElement.innerHTML = xmlhttpRequestFunc.responseText;
}
}
}
}
Codice PHP:
if(isset($_POST['logusername']) && isset($_POST['logpassword'])){
$logusername = $_POST['logusername'];
$logpassword = $_POST['logpassword'];
if(empty($logusername) || empty($logpassword)){
echo "enter username and password";
}else{
echo "your name is ".$logusername." and your password is ".$logpassword;
}
}