【问题标题】:Stop Recaptcha from executing "action" in a form阻止 Recaptcha 在表单中执行“动作”
【发布时间】:2012-08-23 18:16:40
【问题描述】:

我正在尝试使用 jQuery 发布和处理表单。

<form action="/postcomment/" method="post" id="commentform">
  <input type="text" name="author" id="author" />
  <input type="text" name="email" id="email" />
<textarea name="comment" id="comment" ></textarea>
<input name="submit" type="submit" id="submit" value="Submit" />
</form>

以及 jQuery 代码:

$("#submit").click(function() {
$.ajax({
 dataType: 'json',
 beforeSend: function() {
 },
 timeout: 60000,
 error: function(request,error) {
 },
  success: function(data) {
   var obj = jQuery.parseJSON(data);
   //blah blah...
   } // End success
}); // End ajax method
return false;
});

它按预期工作。但是,如果我将 &lt;script type="text/javascript" src="https://www.google.com/recaptcha/api/challenge?k=xxxx" &gt; &lt;/script&gt; 添加到表单中,它将不再起作用。

浏览器会问:有一个json文件,要打开吗?

很明显,recaptcha 脚本调用了“post”操作。如何阻止 Recaptcha 在表单中执行“操作”?

相关问题:Handling json Form with jQuery on Google App Engine

【问题讨论】:

  • 可以在提交表单之前用jquery更改表单的操作吗?
  • 什么意思?使用 jquery 更改表单的操作?

标签: javascript jquery json recaptcha


【解决方案1】:

这就是我所说的改变动作的意思,希望我能理解你的问题:

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
 <script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script>
    <script>
        function changeAction() {
            $("#myForm").attr("action", "anotherAction");
            return false;
        }
    </script>
    <title></title>

</head>
<body>
 <form action="myFirstAction.html" id="myForm"> 
        <input type="text" />
        <button type="submit" onclick="return changeAction()">
        </button>
    </form>
</body>
</html>

点击按钮后,表单的动作是“anotherAction”。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-06-08
    • 1970-01-01
    • 1970-01-01
    • 2015-05-13
    • 1970-01-01
    • 2021-01-11
    • 1970-01-01
    • 2017-04-20
    相关资源
    最近更新 更多