0

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

期待どおりに動作します。ただし、フォームに追加すると<script type="text/javascript" src="https://www.google.com/recaptcha/api/challenge?k=xxxx" > </script>、機能しなくなります。

ブラウザは、次のように尋ねます: json ファイルがあります。それを開きますか?

明らかに、recaptcha スクリプトは「投稿」アクションを呼び出します。Recaptcha がフォームで「アクション」を実行しないようにするにはどうすればよいですか?

関連する質問: Google App Engine で jQuery を使用して json フォームを処理する

4

1 に答える 1

0

これがアクションを変更するという意味です。うまくいけば、私はあなたの質問を理解しています:

<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」です。

于 2012-08-23T18:41:15.420 に答える