How to use $.post request to pass username and password to the server url?
I want to return true or false from that request.
$.post("dtbs.php",{username:userName,password:password},function(result){
});
The above code represents that but I want to pass the true or false value to the text file from that request. I am confused how to do that?
The below is my script:
<script>
$(document).ready(function(){
$("#loginBtn").click(function(){
var userName = $("#inputlUsername3").val();
var password = $("#inputlPassword3").val();
if(userName && password) {
//your php request goes here and return true or false or any ohter response as per your need
$.post("dtbs.php",{username:userName,password:password},function(result){
});
$.ajax({url: "response.txt", success: function(result){
if(result === 'true') {
alert("Redirect it to dashboard");
} else {
alert("Show error");
}
}});
} else {
alert("Plz fill all the field");
}
});
});
</script>
The below represents the dtbs.php
<?php
$uname=$_POST['txtuname'];
$pwd2=$_POST['txtpwd2'];
$con=mysql_connect("localhost","root","") or die(mysql_error());
mysql_select_db("onlineshop",$con);
$r=mysql_query("select password from users where username='$uname'",$con);
$row = mysql_fetch_row($r);
$val=$row[0];
if($val!="")
{
if($pwd2==$val)
{
session_start();
$_SESSION['username']=$uname;
$myfile= fopen("response.txt", "w") or die("unable to open file");
$txt="true";
fwrite($myfile, $txt);
fclose($myfile);
}
else {
$myfile= fopen("response.txt", "w") or die("unable to open file");
$txt="false";
fwrite($myfile, $txt);
fclose($myfile);
}
}
else {
$myfile= fopen("response.txt", "w") or die("unable to open file");
$txt="false";
fwrite($myfile, $txt);
fclose($myfile);
}
?>
suggest me solution.