ajax jquery 中的成功函数没有被 Json 数据类型调用?它总是跳转到错误函数?请告诉我这段代码有什么问题!//jquery ajax 代码
$.ajax({
type: 'GET',
dataType: 'json',
async:false,
contentType:'application/json', data:'fname1='+$('#fname').val()+'&lname1='+$('#lname').val()+'&email1='+$('#email').val()+'&contact1='+$('#contact').val()+'&password1='+$('#password').val(),
beforeSend: function(x){
if(x && x.overrideMimeType){ x.overrideMimeType("application/json;charset=UTF-8");
}
},
url: "./register.php",
success:function(data) {
if(data1.success=="true")
{
$('#register_response').html("<img src='images/36.gif' alt='Signing Up..' />");
$('#dialog').fadeOut('slow');
$('#overlay').fadeOut('slow');
window.location="index.php";
}
},
error: function(data) {
console.log(textStatus, errorThrown); }
});
这是我接受 json 数据的 php 代码!!
//php代码
<?php
$fname=$_POST['fname1'];
$lname=$_POST['lname1'];
$contact=$_POST['contact1'];
$email=$_POST['email1'];
$pass=$_POST['password1'];
require("connect.php");
$qry="SELECT * FROM register WHERE $email='$email'";
$result=mysql_query($qry,$con);
$count=mysql_num_rows($result);
if($count==0)
{
$data = array('success'=>"true");
echo json_encode($data);
$query="INSERT INTO register(fname,lname,contact,email,password)VALUES('$fname','$lname','$contact','$email','$pass')";
$rslt=mysql_query($query,$con);
setcookie("user",$email,time()+36000);
}
else
{
$data = array('success'=>"false");
echo json_encode($data);
}
mysql_close($con);
?>