0

我正在尝试将 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

4

4 回答 4

1

问题是由行中选择器末尾的点引起的$('input[name=customer123...。点没有做任何事情,它使选择器无效。删除这些点应该可以解决问题。希望这可以帮助!

于 2012-08-21T10:51:31.227 回答
1

也许

$("form#form_customer").submit(function(e) {
  e.preventDefault();
});
于 2012-08-21T10:44:47.797 回答
0

您应该以 JSON 格式发送数据,使用:“数据:数据”无效,尝试:

   $.ajax({
        url: "inc/createObject.php",
        type: "POST",
        data:{dataField : data },
于 2012-08-21T10:54:13.253 回答
0

你的代码应该是这样的。

$("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;
        });
于 2012-08-21T11:19:32.430 回答