I am trying to make a simple login page using ajax and php. the response text it is returning is like this: responseText :
<html>
<head>
</head>
<body>
</body>
</html>
success
Why is this happening? How can I get rid of these html tags. my code is:
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.js"></script>
</head>
<body>
<form action="" method="post" id="myform">
<label>Username</label><input type="text" id="username" name="user">
<label>Password</label><input type="text" id="password" name="pwd">
<input type="button" onclick="sub()" value="Submit">
</form>
</body>
</html>
<script>
function sub()
{
var email=$("#username").val();
var password=$("#password").val();
var dataString = 'email='+email+'&password='+password;
if($.trim(email).length>0 && $.trim(password).length>0)
{
$.ajax({
type: "POST",
dataType: "text",
url: "home1.php",
data: "username=" + $("#username").val()+"&password=" + $("#email").val(),
cache: false,
success: function(status){
alert(status);
}
});
}
}
</script>
home1.php:
<?php
include("db.php");
session_start();
if(isSet($_POST['email']) && isSet($_POST['password']))
{
$email=mysqli_real_escape_string($db,$_POST['email']);
$password=mysqli_real_escape_string($db,$_POST['password']);
$result=mysqli_query($db,"SELECT user_id FROM customers WHERE email1='$email' and password='$password'");
$count=mysqli_num_rows($result);
$row=mysqli_fetch_array($result,MYSQLI_ASSOC);
if($count==1)
{
$_SESSION['id']=$row['user_id'];
echo "success";
}
}
?>