$("#submit_login").click(function() {
var username = $('input[name=user_email]').val();
var password = $('input[name=user_password]').val();
$.ajax({
type: "POST",
dataType: "json",
url: "newExam.php",
data: {
name: username,
pwd: password
},
cache: false,
beforeSend: function() {
$("#submit_login").val('Connecting...');
},
success: function(dataa) {
if (dataa) {
alert(dataa);
$("#submit_login").val('success')
} else {
$("#submit_login").val('Login')
alert('nodata')
}
}
});
});
<?php
$servername = "localhost";
$username = "root";
$password = "12345";
$dbname = "uvm_server";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$email_php = $_POST['name'];
$pwd_php=$_POST['pwd'];
echo $email_php;
echo $pwd_php;
$sql = "select name from user where email='$email_php'";
$result = mysqli_query($conn,$sql);
while($row=mysqli_fetch_array($result))
{
echo "<p>".$row['name']."</p>";
$rows[]=$row;
}
echo '{"members":'.json_encode($rows).'}';
?>
当我查看资源时,我能够获得输出。但成功的功能并没有得到充分发挥。我需要SQL查询的输出作为JSON,可以在javascript中访问。这样我就可以验证用户名和密码了。 它总是显示正在连接...我想知道我的ajax调用是否正确
答案 0 :(得分:0)
摆脱<p>
输出,这不是JSON。
while($row=mysqli_fetch_array($result))
{
$rows[]=$row;
}
echo json_encode(array('members' => $rows));