为什么jQuery不提交此表单? (或我做了什么错误?:-p) [英] Why Is jQuery Not Submitting This Form? (Or What Have I Done Wrong? :-p)

查看:144
本文介绍了为什么jQuery不提交此表单? (或我做了什么错误?:-p)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HTML:

 < form action =https://live.sagepay.com/gateway/service/vspform -register.vspmethod =POSTid =sagepay_form> 
< input type =hiddenname =navigatevalue =/>
< input type =hiddenname =VPSProtocolvalue =2.23>
< input type =hiddenname =TxTypevalue =PAYMENT>
< input type =hiddenname =Vendorvalue =******************>
< input type =hiddenid =Cryptname =Cryptvalue =>
< input id =payment_proceedvalue =继续付款class =mws-button greentype =button>
< / form>

JS:

  $(#payment_proceed)。click(function(){
$ .post('/ includes / cart / ajax / sagepay.php',{//此脚本只回应base64
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()
},
函数(crypt){
$(#Crypt)。val(crypt); // base64C rypt字符串插入隐藏表单域中。
alert($(#Crypt)。val()); //我只是把它放在这里以确保它已经收到了Crypt字符串。
$(#sagepay_form)。submit(); //这不起作用...
});
});

我不知道为什么$(#sagepay_form)。不提交表格。我唯一的猜测是因为actionurl是一个远程服务器。如果是这样的话,有没有人知道我可以如何去实现我想要实现的目标?



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

解决方案使用 $(#sagepay_form)。submit(function() ...而不是 $(#payment_proceed)。click(function()


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...
            });
    });

I have no idea why $("#sagepay_form").submit(); does not submit the form. My only guess is it's because the "action" url is a remote server. If this is the case, does anyone know how I can go about what I am trying to achieve?

Thanks, any help would be greatly appreciated.

解决方案

Use $("#sagepay_form").submit(function() ...instead of $("#payment_proceed").click(function().

这篇关于为什么jQuery不提交此表单? (或我做了什么错误?:-p)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆