2

コメントのフォームとして使用します。ページにはこのクラスがたくさんあるので、最も近いフォームを選択する必要がありますが、機能しません。

$(document).ready(function() {
$(".comment_but").on('click',function(){
    var location2 = $(this).closest('div');
    var datastring = $(this).closest('form').serialize();
        $.ajax({
        type: "POST",
        url: "comment_save.php",
        data:  datastring,
        cache   : false,
        success: function(html){
$('.comment_show',location2).html(html);}});});});

そして私のHTML

<div class="comment_show"></div>
<tr>
        <form onSubmit="return false;" name="comment_form" id="comment_form" style=" display:inline; ">
            <td align="right"><textarea name="comment_box" cols="70" rows="2"></textarea></td>
                        <td>
            <input name="post_id" type="hidden" value="<? echo($data['post_id']); ?>" />
            <input name="Send" class="comment_but" value="Comment!" type="submit" /></td>
        </form>
</tr>
4

1 に答える 1

1

onsubmitにコードを入れてください

$(document).ready(function() {
  $("#comment_form").on("submit",function(){
    var datastring=$(this).serialize();
    $.ajax({
      type: "POST",
      url: "comment_save.php",
      data:  datastring,
      cache   : false,
      success: function(html){
        $('.comment_show',location2).html(html);
      }
    });
    return false; // mandatory
  });
});
于 2012-12-06T14:24:52.000 に答える