0

Jqueryを使用して複数のフォームを送信したい(すでに完了しています)が、問題は..送信後にフォームをリストフォームから削除するたびに、これが私のJSPコードです

<form action="searchTweet" method="post">
    <textarea name="searchTxt"></textarea>
    <input type="submit" name="post" value="Search"/>

</form>
 <%
    if(session.getAttribute("twitModel")!=null)
    {

       List<TwitterModel> twit=(List<TwitterModel>)session.getAttribute("twitModel");

       int count=0;
       for(TwitterModel tweet:twit)
    {
           count=count+1;

%>
<p>
    @<%=tweet.getScreenName()%> : <%=tweet.getTweet() %>
   <form id="form2" method="post">
   <input type="hidden"  name="screenName" value="<%= tweet.getScreenName() %>">
   <input type="hidden"  name="tweet" value="<%= tweet.getTweet() %>">
   <input type="submit"  class="update_form" value="Save"> <!-- changed -->
   </form>
    </p>     <%   } }  %>

複数送信フォームの私のJquery

   <script>
   // this is the class of the submit button
   $(".update_form").click(function() { // changed
    $.ajax({
       type: "GET",
       url: "saveSearch",
       data: $(this).parent().serialize(), // changed
       success: function(data)
       {
         $(this).parents('p').remove();
       }
     });
      return false; // avoid to execute the actual submit of the form.
        });

私が間違っていることは何ですか??

ありがとう

よろしく

ダンズ

4

2 に答える 2

1

関数内でグローバル変数にthis変更されたと思います。これを一度試してください:windowsuccess

 $(".update_form").click(function() { // changed
    var me = this;
    $.ajax({
       type: "GET",
       url: "saveSearch",
       data: $(this).parent().serialize(), // changed
       success: function(data)
       {
         $(me).parents('p').remove();
       }
     });
      return false; // avoid to execute the actual submit of the form.
   });

閉鎖について読む

于 2013-11-07T07:29:28.690 に答える
0

this成功ハンドラー内では、クリックされたボタンではなく、ajax オブジェクトを参照します。この場合、クロージャ変数を使用して問題を修正できます。

また、 .parents() の代わりに .closest() を使用しないでください

$(".update_form").click(function () { // changed
    var $this = $(this);
    $.ajax({
        type: "GET",
        url: "saveSearch",
        data: $(this).parent().serialize(), // changed
        success: function (data) {
            $this.closest('p').remove();
        }
    });
    return false; // avoid to execute the actual submit of the form.
});
于 2013-11-07T07:29:46.683 に答える