gpt4 book ai didi

javascript - ajax jquery 总是运行错误;

转载 作者:行者123 更新时间:2023-11-28 06:15:46 24 4
gpt4 key购买 nike

Ajax jquery总是运行错误函数,尽管成功函数运行并且我可以获取 session 值,但我无法运行window.location="profile.php";

$(document).ready(function(){
$("#login").click(function(){
var username=$("#usern").val();
var password=$("#user").val();
$.ajax({
type: "POST",
url: "model/user.php",
data: {
user_log : username,
password : password
},
dataType: 'json',
error: function (xhr,textStatus,errorThrown) {

$("#error").html("<span style='color:#cc0000'>Error:</span> Invalid username and password. ");
},
success: function(json){

window.location="profile.php";

},
beforeSend:function()
{
$("#error").html("<img src='http://www.chinesecio.com/templates/base/images/loading.gif' /> Loading...")
}
});
return false;
});
});

用户.php

<?php 
ob_start();
session_start();
error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED);
require_once(dirname(__FILE__).'/../model/connect.php');
?>
<?php
global $pdo;

if(isset($_POST['user_log'])) {
// username and password sent from Form
$username=$_POST['user_log'];
$password=$_POST['password'];
$qr= "SELECT * FROM user where username='$username' AND password='$password'" ;
$stmt= $pdo->query($qr);
$row= $stmt->fetch(PDO::FETCH_ASSOC);
if($stmt->rowCount() > 0)
{
$_SESSION['id']=$row['id'];
$_SESSION['name_mem']=$row['username'];
$_SESSION['level_mem']=$row['level'];
}
header("location:../../../../index.php");
}
?>

最佳答案

删除此行:

header("location:../../../../index.php");

如果上述不起作用,请从 ajax 属性中忽略此内容:

dataType: 'json',

关于javascript - ajax jquery 总是运行错误;,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35981346/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com