我正在序列化我的表单数据,记录它,然后将其发送到 PHP 文件,它在哪里返回 null。
jQuery:
$('#preregister').submit(function () {
if(checkemail("prereg_email")) {
var data;
data = $(this).serialize();
console.log(data);
$('#imageloader').fadeIn();
$.ajax({
url: '/docs/adduser.php',
data: data,
processData: false,
contentType: false,
type: 'POST',
success: function ( data ) {
//console.log(data); //returns a string of the data.
var data = JSON.parse(data); //parses the string into an object.
console.log(data); //logs the object.
if (data.error) { alert(data.message); }
}
});
}
return false;
});
PHP:
<?php
$Return = array();
$Return["in"] = $_POST;
$Return["error"] = false;
$Return["message"] = "Nothing has happened.";
/* EMAIL */
$in_email = urldecode($_POST["prereg_email"]);
$Return["in_email"] = $in_email;
if (!filter_var($in_email, FILTER_VALIDATE_EMAIL)) {
$Return["error"] = true;
$Return["message"] = "Enter a valid email.";
}
if (!$in_email) {
$Return["error"] = true;
$Return["message"] = "Enter an email.";
}
str_replace('\\/', '/', json_encode($Return));
echo json_encode($Return);
?>
当数据回来时,它说:
Object {in: Array[0], error: true, message: "Enter an email.", in_email: ""}
这很奇怪,因为在我发送数据之前,我记录了它,它显示:
prereg_email=rbross3%40gmail.com
所以...我至少应该是$Return["prereg_email"]
正确的?