Jquery通过.submit()提交一个关于AJAX成功的表单......怎么样?

时间:2022-11-24 12:24:46

I'm trying to send all form data to a script via AJAX by binding a click function to the submit button, setting it to return false so it doesn't submit the form yet. Once AJAX is done with success, I'd like to submit the form by doing: $("#myform").submit(); But nothing happens.

我试图通过AJAX将所有表单数据发送到脚本,方法是将click函数绑定到submit按钮,将其设置为false,这样它就不会提交表单了。一旦AJAX成功完成,我想提交表单:$(“#myform”)。submit();但没有任何反应。

Everything works except for $("#customOrderForm").submit();

一切都有效,除了$(“#customOrderForm”)。submit();

This is for a Paypal payment. Form data gets stored in a session, users go make they payment, return to the website once they successfully made the payment, form data gets send to customers and company via email.

这是Paypal付款。表格数据存储在会话中,用户进行支付,一旦成功付款就返回网站,表格数据通过电子邮件发送给客户和公司。

$("#submit").click(function () {

    var thedata = $("#customOrderForm").serialize();

    $.ajax({
        type: 'POST',
        url: 'buy-custom-session.php',
        cache: false,
        data: thedata,
        beforeSend: function () {
            $('#sessionholder').append('<div class="loading"><img src="loading.gif" alt="loading..." /></div>');
        },
        success: function (data) {
            //$(".loading").detach();
            //$(".error").detach();
            //$('#sessionholder').append(data);
            $("#customOrderForm").submit();
        },
        error: function () {
            $('#sessionholder').append('<p class="error"><strong>Oops!</strong> Try that again in a few moments.</p>');
        }
    });

    return false;

});

HTML FORM

HTML表格

<form id="customOrderForm" action="https://www.paypal.com/cgi-bin/webscr" method="post">

<!-- form fields etc -->

<input type="image" name="submit" id="submit" src="https://www.paypalobjects.com/en_AU/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" />

</form>

No ERRORS in Firebug.

Firebug中没有错误。

AJAX success executes.

AJAX成功执行。

Cheers

干杯

1 个解决方案

#1


6  

Change the name and id of the image-input.

更改图像输入的名称和ID。

From the jQuery-docs: Forms and their child elements should not use input names or ids that conflict with properties of a form, such as submit, length, or method. Name conflicts can cause confusing failures.

从jQuery-docs:Forms及其子元素不应使用与表单属性冲突的输入名称或id,例如submit,length或method。名称冲突可能导致令人困惑的失败。

Example : http://jsfiddle.net/doktormolle/XNMEF/

示例:http://jsfiddle.net/doktormolle/XNMEF/

#1


6  

Change the name and id of the image-input.

更改图像输入的名称和ID。

From the jQuery-docs: Forms and their child elements should not use input names or ids that conflict with properties of a form, such as submit, length, or method. Name conflicts can cause confusing failures.

从jQuery-docs:Forms及其子元素不应使用与表单属性冲突的输入名称或id,例如submit,length或method。名称冲突可能导致令人困惑的失败。

Example : http://jsfiddle.net/doktormolle/XNMEF/

示例:http://jsfiddle.net/doktormolle/XNMEF/