简体   繁体   中英

Stop Recaptcha from executing “action” in a form

I am trying to use jQuery to post and process a form.

<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>

and the jQuery code:

$("#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;
});

It works as expected. However, If I add the <script type="text/javascript" src="https://www.google.com/recaptcha/api/challenge?k=xxxx" > </script> into the form, it no longer works.

The browser will ask: There is a json file, do you want to open it?

Obviously the recaptcha script invoke the "post" action. How can I Stop Recaptcha from executing "action" in a form?

Related Question: Handling json Form with jQuery on Google App Engine

This is what I mean by changing the action, hopefully I am understanding your question:

<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>

After clicking the button the form's action is "anotherAction".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM