[英]Why am i not getting anything from php?
$('#registerForm').submit(
function()
{
callAjaxSubmitMethod(this);
//event.preventDefault();
}
);
It is the function inside my dom ready. 这是我的dom内部准备好的功能。
function callAjaxSubmitMethod(form)
{
$.ajax({
type: "POST",
url: "lib/registration_validate.php",
data: $("#registerForm").serialize(),
success: function(response)
{
alert("s"+response.status);
},
error:function(response)
{
alert("e"+response);
}
});
}
It is actual function definition. 它是实际的功能定义。
My php contents are 我的PHP内容是
<?php
include 'configdb.php';
session_start();
global $connection;
echo "oops";
if(isset($_POST['submit']) && $_POST['email']!='' && $_POST['password']!='')
{ //use empty....
$email= $_POST['email'];
$sql1 = "SELECT * FROM Users WHERE emailID = '$email'";
$result1 = mysqli_query($connection,$sql1) or die("Oops");
if (mysqli_num_rows($result1) > 0)
{
$_SESSION['email_exist']="Email Already Exists";
//die({'status':'Email Already Exists'});
//echo var_dump($_SESSION);
//echo '{status:0}' ;
//exit;
}
}
?>
I din't get any alerts. 我没有收到任何警报。 If i enable event.preventDefault()
I am getting out of memory error
in mozilla and sundefined
alert in chrome. 如果我启用event.preventDefault()
, sundefined
out of memory error
Mozilla out of memory error
和chrome中的sundefined
警报的情况。
Use 采用
if(isset($_POST['submit']) && $_POST['email']!='' && $_POST['password']!='')
{ //use empty....
$email= $_POST['email'];
$sql1 = "SELECT * FROM Users WHERE emailID = '$email'";
$result1 = mysqli_query($connection,$sql1) or die("Oops");
$response = array();
if (mysqli_num_rows($result1) > 0)
{
$_SESSION['email_exist']="Email Already Exists";
$response['status']='Email Already Exists';
}
else{
$response['status']='Allis OK';
}
echo json_encode($response); die;
}
And in ajax , add: 然后在ajax中,添加:
dataType:'json'
Edit 编辑
For your info , how to set dataType : 对于您的信息,如何设置dataType:
$.ajax({
type: "POST",
dataType:'json',
url: "lib/registration_validate.php",
data: $("#registerForm").serialize(),
success: function(response)
{
alert("s"+response.status);
},
error:function(response)
{
alert("e"+response);
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.