I used post method to send data (username and password ) from xdk app to php file by XMLHttpRequest object,but i faced a problem. all data i sent by post method undefined in php file.I don't know where the error.
this xdk code
<!DOCTYPE html> <html lang="en-US"> <head> <meta charset="UTF-8"> <link rel="stylesheet" href="css/style.css" media="screen" type="text/css" /> <script type="text/javascript"> function createXHR(){ if(typeof XMLHttpRequest !="undefined") return new XMLHttpRequest(); else return new ActiveXObject("Microsoft.XMLHttp"); } function sendRequest(){ var pname=document.getElementById("txtName").value; var pGender=document.getElementById("rdoGender").value; var pMail=document.getElementById("txtMail").value; var pCity=document.getElementById("txtCity").value; var pBDate=document.getElementById("txtBDate").value; var str ="txtName="+pname+"&txtgender="+pGender+"&txtemail="+pMail+"&txtcity="+pCity+"&txtdate="+pBDate; // alert(str); var oXmlHttp= createXHR(); oXmlHttp.open("post","http://localhost/hospital/post_data.php","true"); oXmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); oXmlHttp.onreadystatechange=Function(){ if(oXmlHttp.readyState==4){ if(oXmlHttp.status==200 || oXmlHttp.status == 304) divStatus.innerHTML=+ oXmlHttp.responseText; else divStatus.innerHTML=+ oXmlHttp.statusText; }//end if }; //end ready state oXmlHttp.send(str); } </script> </head> <body> <form method="post" action="http://localhost/hospital/post_data.php" onsubmit="sendRequest(); return false;" > <p>enter patient information</p> <p>NAME <input type="text" id="txtName" /> </p> <p>Male <input type="radio" value="M" name="rdoGender" id="rdoGender" /> <p>Female <input type="radio" value="F" name="rdoGender" id="rdoGender"/> </p> <p>EMAIL <input type="email" id="txtMail"/> </p> <p>city <input type="text" id="txtCity"/> </p> <p>date <input type="date" id="txtBDate"/> </p> <input type="submit" value="save"/> </form> <div id="divStatus"></div> </body> </html>
this is php code
<?php header("Content_Type: text/plain"); $link = mysqli_connect("localhost", "root", "", "hospital"); /* check connection */ if (mysqli_connect_errno()) { echo mysqli_connect_error(); header("HTTP/1.0 500 Internal Server Error"); exit(); } if(isset($_POST["txtName"])) { $pname=$_POST["txtName"]; $pgender= $_POST["txtgender"]; $pemail= $_POST["txtemail"]; $pdate= $_POST["txtdate"]; $pcity= $_POST["txtcity"]; } $insert="insert into 'hospital'.'patient' (`PName`, `Gender`, `email`, `BDate`, `city`) VALUES ($pname,$pgender,$pemail,$pdate,$pcity)"; if ($result = mysqli_query($link, $query)) echo "Patient data added successfully "; else echo "Patient data not added successfully "; mysqli_close($link); ?>