使用 JS 提交 PayPal 表单不起作用
我有一个 PayPal 表单,如下所示:(使用 jQuery 添加一些字段)
<form method="post" action="https://www.paypal.com/cgi-bin/webscr"> <input type="hidden" value="_s-xclick" name="cmd"> <input type="hidden" value="sdfgsdfg" name="hosted_button_id"> <input type="button" value="Purchase One Year License" name="submit" class="pp_button" id="35" style="background-color: rgb(255, 255, 255);"> <input type="hidden" value="35" name="cs_project_id"> <input type="hidden" value="6d04c7a241ad4415eb194a90dc252b09" name="cs_transaction_id"> </form>
我尝试使用第三个 input
元素 (type="button"
) 提交表单使用这段代码:
$(".pp_button").click(function() { var button = $(this); button.parent().submit(); });
这应该可以正常工作,对吧?我使用 var button
是因为 click()
函数中的其他部分。我已经检查了 button.parent()
的 tagName
,它以 FORM
的形式给出,所以没关系......
我做错了什么这里?这通常工作正常...是因为我从 AJAX 调用插入标签(最后两个 input
标签)吗?还有别的事吗?我的桌子上缺少成熟的切达干酪吗?
谢谢,
詹姆斯
I have a PayPal form as follows: (some fields are added using jQuery)
<form method="post" action="https://www.paypal.com/cgi-bin/webscr"> <input type="hidden" value="_s-xclick" name="cmd"> <input type="hidden" value="sdfgsdfg" name="hosted_button_id"> <input type="button" value="Purchase One Year License" name="submit" class="pp_button" id="35" style="background-color: rgb(255, 255, 255);"> <input type="hidden" value="35" name="cs_project_id"> <input type="hidden" value="6d04c7a241ad4415eb194a90dc252b09" name="cs_transaction_id"> </form>
I'm trying to submit the form using the 3rd input
element (type="button"
) using this code:
$(".pp_button").click(function() { var button = $(this); button.parent().submit(); });
This should work fine right? I'm using var button
because of other parts later in the click()
function. I've checked the tagName
of button.parent()
and it's given as FORM
, so that's fine...
What have I done wrong here? This usually works fine... Is it because I'm inserting tags (the last two input
tags) from an AJAX call? Something else? A lack of mature cheddar on my desk?
Thanks,
James
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为什么不将输入类型从
button
设置为submit
呢?这将使按钮提交表单并且不需要任何Javascript?或者,如果您想使用 javascript (jQuery),您可以为表单指定一个 ID,如下所示:
当您想提交表单时,您可以调用:
Why don't you just set the input type from
button
tosubmit
? This would make the button submit the form and not need any Javascript?Or if you want to use javascript (jQuery), you could give the form an ID like this:
And when you want to submit the form you can call:
您有一个名为
submit
的表单控件。这会用HTMLElementNode
破坏submit
函数。最好的解决方案可能是不要在这里使用 JavaScript。你说你需要发生其他事情,但用户可能关闭了 JS,所以如果它们很重要,你几乎肯定会更好地找到不同的方式。
简单的解决方案是更改名称。
复杂的解决方案是从另一个表单获取提交方法的副本,然后将其与您要提交的表单一起使用:
You have a form control named
submit
. This clobbers thesubmit
function with anHTMLElementNode
.The best solution is probably to not use JavaScript here. You say that you need other things to happen, but the user might have JS turned off, so if they are important you would almost certainly be better off finding a different way.
The simple solution is to change the name.
The complicated solution would be to get a copy of the submit method from another form, then use it with the form you want to submit: