它适用于localhost但不适用于服务器I.另一个警告是 主线程上的同步XMLHttpRequest由于其对最终用户体验的不利影响而被弃用。如需更多帮助,请查看...
这是我的表格:
<form action ="" method="post" id="frmlogin" class="text" onsubmit="return flogin();">
<input type="text" name="user" id="email" placeholder="Username*" required>
<input type="password" name="pass" id="password" placeholder="Password*" required>
<input type="submit" name="login" class="login loginmodal-submit" value="Login">
这是我的Javascript:
<script>
function flogin() {
$("#errorlog").html("");
var email = document.getElementById('email').value;
var password = document.getElementById('password').value;
var request = $.ajax({
type: 'post',
url: 'action/login_action.php',
contentType: "application/json; charset=utf-8",
dataType: "json",
data: {email: email, password: password, login: "login"},
success: function (response) {
var res = parseInt(response.trim());
alert(response);
if (response.trim() == "10") {
$("#errorlog").html("Email and Password is must");
//alert(response);
}
else if (res >= 1) {
//alert(response);
document.getElementById('email').value = "";
document.getElementById('password').value = "";
window.location = "index.php";
}
else {
$("#errorlog").html("E-mail or Password is incorrect");
}
}, error: function (response) {
alert("FAIL");
alert(response);
//alert(response[0]);
//response is json you need to parse it
// var json = response,
// obj = JSON.parse(json);
// alert(response.length);
// alert(response.length);
}
});
return false;
}
</script>
php代码:
<?php
error_reporting(1);
if (!isset($_SESSION)) {
session_start();
}
require_once("../config/encrypt.php");
require_once '../config/functions.inc';
require_once '../config/database.php';
///////////////login check////////////
if ($_POST['login'] == "login") {
echo "fdgdffdf";
if (empty($_POST['password']) or empty($_POST['email'])) {
echo "10";
exit;
} else {
$en = new Encryption();
$password = trim($_POST['password']);
$email = $en->removeBadChars(trim($_POST['email']));
$db = new Database();
if ($db->open())
$password = sha1($password);
{
$sql = "select * from phpap105_signup where email='$email' and password='$password'";
// echo "select * from phpap105_signup where email='$email' and password='$password'";
//exit;
$res = mysqli_query($db->resourse(), $sql);
$cou = mysqli_num_rows($res);
if ($cou >= 1) {
$row = mysqli_fetch_array($res);
$_SESSION['client_user_id'] = $row[0];
$_SESSION['client_user_id1'] = $row[0];
$_SESSION['client_username'] = $row[1];
$_SESSION['client_logged'] = true;
// $_SESSION['adm_status'] = $row['status'];
$r = "success";
} else {
$r = "fail";
}
echo $cou;
// exit;
}
}
echo $r;
}
/////login end/////////////////
?>