我正在尝试将 ajax 表单提交添加到我正在使用 jquery 开发的 PHP Web 应用程序。表单正在提交并写入数据库,但它仍然会通过刷新来完成这一切。
这是我的代码:
$("form#form_customer").submit(function() {
var customer123first_name = $('input[name=customer123first_name.]');
var customer123last_name = $('input[name=customer123last_name.]');
var customer123date_of_birth = $('input[name=customer123date_of_birth.]');
var customer123email_address = $('input[name=customer123email_address.]');
var customer123telephone_number = $('input[name=customer123telephone_number.]');
var customer123picture = $('input[name=customer123picture.]');
var customer123id_picture = $('input[name=customer123id_picture.]');
var customer123id_expiration = $('input[name=customer123id_expiration.]');
var data = 'customer123first_name=' + customer123first_name.val() + '&customer123last_name=' + customer123last_name.val() + '&customer123date_of_birth=' + customer123date_of_birth.val() + '&customer123email_address=' + customer123email_address.val() + '&customer123telephone_number=' + customer123telephone_number.val() + '&customer123picture=' + customer123picture.val() + '&customer123id_picture=' + customer123id_picture.val() + '&customer123id_expiration=' + customer123id_expiration.val();
$.ajax({
url: "inc/createObject.php",
type: "POST",
data: data,
cache: false,
success: function(data){
$('form_success').fadeIn();
}
});
return false;
});
我在网上阅读的有关此特定问题的所有内容都发现 return false;
调用位于错误的位置或根本不存在。我检查过我的位置是否正确,只是找不到它令人耳目一新的原因。
我知道 jquery 正在工作,因为我用它来做弹出窗口,效果很好。
如果您想查看上下文中的代码,请访问 www.sfyfe.com/studioadmin
最佳答案
问题是由 $('input[name=customer123...
行上选择器末尾的点引起的。该点没有做任何事情,它使选择器无效。删除点应该可以解决问题。希望这会有所帮助!
关于php - Jquery表单提交依然清爽,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12053128/