我正在使用引导注册表单获取用户信息并将它们存储在我的数据库中我使用ajax
请求提交表单信息并在验证后存储它。
信息经过正确验证,然后正确存储在我的数据库中。
问题是存储信息后请求没有返回响应。
这是验证引导代码和 ajax 请求:
$(document).ready(function(){
//To validate the registration form and save its value after validation
$('#registerForm').bootstrapValidator({
message: 'This value is not valid',
feedbackIcons: {
valid: 'glyphicon glyphicon-ok',
invalid: 'glyphicon glyphicon-remove',
validating: 'glyphicon glyphicon-refresh'
},
fields: {
email: {
validators: {
notEmpty: {
message: 'The email is required and cannot be empty'
},
emailAddress: {
message: 'The input is not a valid email address'
}
}
}
}
})
.on('success.form.bv', function(e) {
// Prevent form submission
e.preventDefault();
// Get the form instance
var $form = $(e.target);
// Get the BootstrapValidator instance
var bv = $form.data('bootstrapValidator');
// Use Ajax to submit form data
$.ajax({
type: "POST",
url: $form.attr('action'),
data:$(form).serialize(),
dataType: "json",
success: function(data)
{
alert(data);
},
error : function(XMLHttpRequest, textStatus, errorThrown) {
alert(XMLHttpRequest);
alert(textStatus);
alert(errorThrown);
alert(XMLHttpRequest.responseText);
}
});
});
});
ajax 函数不会像我所说的那样进入任何success
orerror
函数内部,它可以正常工作并正确存储所有内容,但它不会返回 ajax 函数,而是在浏览器中打印响应。
这也是 php 页面:
<?PHP
$server_root = "../";
include_once("{$server_root}include-sql/mysql.class.php");
include_once("{$server_root}config.php");
Global $db1;
$db1 = new db_mysql($conf['db_hostname'], $conf['db_username'], $conf['db_password'], $conf['db_name']);
$db1->query("SET NAMES utf8");
date_default_timezone_set('Asia/Istanbul');
$email = mysql_real_escape_string($_POST['email']);
$sql = $GLOBALS['db1']->query("INSERT INTO users (email) VALUES ('$email')");
if($sql)
{
$msg = 'Success';
}
echo json_encode($msg);
?>
msg
提交后打印我无法提醒它,因为它没有返回ajax成功功能???这段代码有什么问题还是我错过了什么?