php - 为什么 jQuery 不提交此表单? (或者我做错了什么?:-p)

标签 php jquery forms submit opayo

HTML:

<form action="https://live.sagepay.com/gateway/service/vspform-register.vsp" method="POST" id="sagepay_form"> 
    <input type="hidden" name="navigate" value="" />
    <input type="hidden" name="VPSProtocol" value="2.23">
    <input type="hidden" name="TxType" value="PAYMENT">
    <input type="hidden" name="Vendor" value="******************">
    <input type="hidden" id= "Crypt" name="Crypt" value="">
    <input id="payment_proceed" value="Proceed To Payment" class="mws-button green" type="button">
</form>

JS:

$("#payment_proceed").click(function() {
        $.post('/includes/cart/ajax/sagepay.php', { //This script just echos the base64 "Crypt" string required by sagepay.
                "cart_id": <?php echo $cart_id; ?>,
                "title": $("#title").val(),
                "first_name": $("#first_name").val(),
                "last_name": $("#last_name").val(),
                "telephone": $("#telephone").val(),
                "email": $("#email").val(),
                "line1": $("#line1").val(),
                "line2": $("#line2").val(),
                "line3": $("#line3").val(),
                "town": $("#town").val(),
                "county": $("#county").val(),
                "postcode": $("#postcode").val()
            },
            function(crypt){              
                $("#Crypt").val(crypt); //The base64 "Crypt" string is inserted in to the hidden form field here.
                alert($("#Crypt").val()); //I just put this here to make sure it had received the "Crypt" string.
                $("#sagepay_form").submit(); //This doesn't work...
            });
    });

我不知道为什么 $("#sagepay_form").submit();不提交表格。我唯一的猜测是这是因为“action”url 是远程服务器。如果是这种情况,有谁知道我该如何实现我想要实现的目标?

谢谢,任何帮助将不胜感激。

最佳答案

使用 $("#sagepay_form").submit(function() ...而不是 $("# payment_proceed").click(function()

关于php - 为什么 jQuery 不提交此表单? (或者我做错了什么?:-p),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13207815/

相关文章:

php - 纯 html 中的 Facebook/Twitter "Like"按钮

php - symfony 4 中没有服务 FOSJsRoutingBundle

jquery - Selectize.js创建: validate CREATE input

javascript - 如何使用 jquery/javascript 分割字符串,输出为 "1,2,222,FF-GA"

javascript - 揭示形式没有出现

javascript - 如果勾选复选框并隐藏字段,则将匿名电子邮件添加到字段

php - 为什么 Codeigniter 的查询生成器返回错误的 MySQL 查询两次?

php - 查找图像文件路径并将其添加到 mySQL

javascript - $(window).width() 在正常状态下和在检查元素上的响应状态下的区别

forms - 使用flask wtform DateTimeField 的无效日期时间格式的自定义错误消息