$.ajax() success函数不执行,但数据插入成功。 230
$("#btn").click(function(){if(($(".html").hasClass("bg-img"))&&($(".inner").hasClass(...
$("#btn").click(function(){
if(($(".html").hasClass("bg-img"))&&($(".inner").hasClass("bg-img"))&&($(".inner2").hasClass("bg-img"))){
var uname=$("#phone").val();
var upwd=$("#pswd").val();
$.ajax({
type:'post',
url:'data/form2.php',
data:{"uname":uname,"upwd":upwd},
success:function(result){
if(result.msg=='succ'){
$(".sub>form").addClass("dsp");
$(".change") .removeClass("dsp");
}else{
alert("注册失败")
}
},
error: function(){
alert(arguments[1]);
}
})
}else{
alert("注册信息错误")
}
});
下面是php代码
header('Content-Type:application/json;charset=utf-8');
//header('Content-Type: text/plain');
@$uname = $_REQUEST['uname'];
@$upwd = $_REQUEST['upwd'];
$conn=mysqli_connect('127.0.0.1','root','','wen',3306);
$sql='SET NAMES UTF8';
mysqli_query($conn,$sql);
//保存用户
$sql = "INSERT INTO user VALUES(NULL,'$uname','$upwd')";
$result = mysqli_query($conn,$sql);
$output=[];
if($result){
$output['msg']='succ';
$output['userid']=mysqli_insert_id($conn);
}else {
$output['msg']='err';
$output['userid']=$sql;
}
echo json_encode($output);
我只有那么多财富值了,大神啊 展开
if(($(".html").hasClass("bg-img"))&&($(".inner").hasClass("bg-img"))&&($(".inner2").hasClass("bg-img"))){
var uname=$("#phone").val();
var upwd=$("#pswd").val();
$.ajax({
type:'post',
url:'data/form2.php',
data:{"uname":uname,"upwd":upwd},
success:function(result){
if(result.msg=='succ'){
$(".sub>form").addClass("dsp");
$(".change") .removeClass("dsp");
}else{
alert("注册失败")
}
},
error: function(){
alert(arguments[1]);
}
})
}else{
alert("注册信息错误")
}
});
下面是php代码
header('Content-Type:application/json;charset=utf-8');
//header('Content-Type: text/plain');
@$uname = $_REQUEST['uname'];
@$upwd = $_REQUEST['upwd'];
$conn=mysqli_connect('127.0.0.1','root','','wen',3306);
$sql='SET NAMES UTF8';
mysqli_query($conn,$sql);
//保存用户
$sql = "INSERT INTO user VALUES(NULL,'$uname','$upwd')";
$result = mysqli_query($conn,$sql);
$output=[];
if($result){
$output['msg']='succ';
$output['userid']=mysqli_insert_id($conn);
}else {
$output['msg']='err';
$output['userid']=$sql;
}
echo json_encode($output);
我只有那么多财富值了,大神啊 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询