我有一个我正在构建的注册表单,应该处理表单提交的AJAX代码会一直返回parseerror。 我正在使用Material Design Framework。
这是jQuery代码:
//表单提交
$form.submit(function () {
$('html, body').animate({
scrollTop: 0
}, 800);
$.ajax({
type: "POST",
url: '/libraries/signup.php',
dataType: "text",
data: {
firstName: $fName.val(),
otherNames: $oName.val(),
userEmail: $uEmail.val(),
phoneNumber: $pNumber.val(),
userPassword: $uPassword.val(),
userGender: $gender.val(),
accType: $accType.val(),
submit: 'Sign Up'
},
beforeSend: function () {
$("input[type=submit]").prop("disabled", true);
$("#p2").fadeIn(120);
$("div.error").fadeOut(380).empty();
showToast("Please Wait...");
},
success: function (response) {
$("input[type=submit]").prop("disabled", false);
if (response.type === "success") {
showToast(response.content);
} else {
$("div.error").slideUp().html(response.content).fadeIn(500);
setTimeout('$("div.error").fadeOut(500);', 3500);
$("#p2").fadeOut(320);
}
},
error: function (jXHR, textStatus) {
$("input[type=submit]").prop("disabled", false);
$("div.error").slideUp().html("Couldn't submit request: " + textStatus).fadeIn(500);
setTimeout('$("div.error").fadeOut(500);', 5500);
$("#p2").fadeOut(320);
}
});
return false;
});
这是PHP:
//Configurations File
include dirname(__FILE__)."/functions.php";
//Check Form Submission
if($_SERVER['REQUEST_METHOD'] == "POST" && $_POST['submit'] == "Sign Up"){
//Sanitize and Encrypt User Input
$firstName = filterUserInput($_POST['firstName']);
$otherNames = filterUserInput($_POST['otherNames']);
$userEmail = filterUserInput($_POST['userEmail']);
$phoneNumber = filterUserInput($_POST['phoneNumber']);
$userPassword = filterUserInput($_POST['userPassword']);
$gender = filterUserInput($_POST['userGender']);
$accountType = filterUserInput($_POST['accType']);
registerMember($firstName, $otherNames, $userEmail, $phoneNumber, $userPassword, $gender, $accountType, $db);
}
我尝试了几种方法并在线查看了这么多解决方案,但问题仍然存在。 任何帮助都非常感谢。