Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/423.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/288.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用jQuery按类刷新div_Javascript_Php_Jquery_Html - Fatal编程技术网

Javascript 使用jQuery按类刷新div

Javascript 使用jQuery按类刷新div,javascript,php,jquery,html,Javascript,Php,Jquery,Html,我使用foreach循环使用PHP进行表渲染 @foreach ($comments as $comment) <tr> <td>{{ $comment->lot_date }} <br> @if (count($comment->ourcar) >= 1)

我使用foreach循环使用PHP进行表渲染

@foreach ($comments as $comment)

                <tr>
                    <td>{{ $comment->lot_date }}
                        <br>
                        @if (count($comment->ourcar) >= 1)
                            <p>Saved</p>
                        @else
                            <form method="POST" action="/comments/{{ $comment->id }}/ourcars">
                                {{ csrf_field() }}
                                <button type="submit" class="btn btn-xs btn-primary">Our Car</button>
                            </form>
                        @endif
                    </td>
                    <td>
                        <a href="{{ route('comments.show', $comment->id) }}">{{ $comment->bid }}</a>
                    </td>
                    <td>{{ $comment->auction_name }}</td>
                    <td class="block">
                        @foreach(explode('#', $comment->pics_urls, 3) as $pic)
                            <a href="{{ $pic }}" class='iframe'>
                                <img src="{{ $pic }}" class="img-fluid" width="30" height="32">
                            </a>
                        @endforeach
                    </td>
                    <td>{{ $comment->company }}</td>
                    <td>{{ $comment->model_name_en }}</td>
                    <td>{{ $comment->model_type_en }}</td>
                    <td>{{ $comment->grade_en }}</td>
                    <td>{{ $comment->model_year_en }}</td>
                    <td>{{ $comment->color_en}}</td>
                    <td>{{ $comment->displacement }}</td>
                    <td>{{ $comment->transmission_en }}</td>
                    <td>{{ $comment->scores_en }}</td>
                    <td>{{ $comment->mileage_num }}</td>
                    <td>{{ $comment->start_price_en }}</td>
                    <td><div class="comment-body">{{ $comment->body }}</div></td>
                    <td>{{ $comment->lot->result_en or '---' }}</td>
                    <td>{{ $comment->user->name }}
                    <td>
                        <button data-id="{{ $comment->id  }}" class="btn-link editButton"><span class='glyphicon glyphicon-edit'></span></button>
                    </td>
                    <td>
                        <form method="POST" action="{{route('comments.destroy', ['id' => $comment->id]) }}">
                            {{ method_field('DELETE') }}
                            {{ csrf_field() }}
                            <div class="form-group">
                                <button type="submit" class="btn-link" onclick="return confirm('Are you sure?')"><span class='glyphicon glyphicon-trash' style="color:red"></span></button>
                            </div>
                        </form>
                    </td>

                </tr>

            @endforeach
@foreach($comments作为$comment)
{{$comment->lot_date}

@如果(计数($comment->ourcar)>=1) 拯救

@否则 {{csrf_field()}} 我们的车 @恩迪夫 {{$comment->auction_name} @foreach(分解(“#”,$comment->pics_url,3)为$pic) @endforeach {{$comment->company} {{$comment->model_name_en} {{$comment->model_type_en} {{$comment->grade_en} {{$comment->model_year_en} {{$comment->color_en} {{$comment->displacement} {{$comment->transmission_en} {{$comment->scores\u en} {{$comment->里程数} {{$comment->start_price_en} {{$comment->body} {{$comment->lot->result\u en或'--'} {{$comment->user->name} {{method_field('DELETE')} {{csrf_field()}} @endforeach
我创建了一个模式窗口,使用JS向行中添加注释。在我提交评论和模式后,我想刷新
comment

所以我在按类刷新div时遇到了一个问题,我可以使用id,因为表是循环的:

$(function() {
            $('.editButton').click(function (e) {
                var button = $(this);

                var geturl = '/comments/' + button.data('id') + '/edit';

                var posturl = '/comments/' + button.data('id');

                $.get(geturl)
                    .done( (response) => {
                        bootbox.dialog( {
                            title : "Add comment",
                            message : response,
                            buttons : {
                                addButton : {
                                    label : 'Add comment',
                                    className : 'btn btn-primary',
                                    callback: () => {
                                        var modalForm = $('#modalForm');

                                        if ($('#commentBody').val()) {
                                            $.ajax({
                                                type : 'POST',
                                                url : posturl,
                                                data : modalForm.serialize(),
                                                success : (response) => {
                                                    if (response === "ok") {
                                                        bootbox.hideAll();
                                                        $('.comment-body').toggle();


                                                    }
                                                }
                                            })
                                        }
                                        return false;
                                    }
                                },
                                closeButton : {
                                    label : 'Close',
                                    className : 'btn btn-default'
                                }
                            }
                        })
                    })
                    .fail( ( errorResponse ) => {
                        bootbox.alert('Error! Comment is not added');
                    });

            });

        });
    </script> 
$(函数(){
$('.editButton')。单击(函数(e){
var按钮=$(此按钮);
var geturl='/comments/'+button.data('id')+'/edit';
var postrl='/comments/'+button.data('id');
$.get(geturl)
.完成((响应)=>{
启动对话框({
标题:“添加评论”,
信息:回应,
按钮:{
添加按钮:{
标签:“添加注释”,
类名:“btn btn主”,
回调:()=>{
var modalForm=$(“#modalForm”);
if($('#commentBody').val()){
$.ajax({
键入:“POST”,
网址:postrl,
数据:modalForm.serialize(),
成功:(回应)=>{
如果(响应=“确定”){
bootbox.hideAll();
$('.comment body').toggle();
}
}
})
}
返回false;
}
},
关闭按钮:{
标签:“关闭”,
类名:“btn btn默认”
}
}
})
})
.失败((错误响应)=>{
bootbox.alert('错误!未添加注释');
});
});
});
我的模态视图:

<div class="modal-body">
    <form action="#" id="modalForm" data-id="{{ $comment->id }}">
        <div class="form-group">
            {{ csrf_field() }}
            {{ method_field('PUT') }}
            <textarea name="body" id="commentBody"
                      placeholder="Add Your Comment Here." class="form-control" required>{{ $comment->body }}</textarea>
        </div>
    </form>
</div>

{{csrf_field()}}
{{method_字段('PUT')}
{{$comment->body}
结果是:

我尝试使用
$('.comment body').toggle()但它不工作。编辑评论后,我应该如何刷新该div

$('.comment-body').('');
试试这个或者

$('.comment-body').html('');
试试这个或者

$('.comment-body').html('');

设置元素的innerHTML以填充它,或使用空字符串清除它:

$('.comment-body').html("New Comment") // New contents
$('.comment-body').html("") // Clear contents
如果在表的多行中有
.comment body
,并且只想“刷新”其中一行,则需要指定一个id,以便可以精确定位包含单元格的行。例如

<tr id="row1"><td class="comment-body">..comment..</td><tr>

$("#row1").find(".comment-body").html("New Comment Text")
。注释。。
$(“#行1”).find(“.comment body”).html(“新注释文本”)

注意:除了
.html
之外,您还可以使用
.text
来防止用户评论中的html代码被注入页面。

设置元素的内部html以填充它,或者使用空字符串清除它:

$('.comment-body').html("New Comment") // New contents
$('.comment-body').html("") // Clear contents
var old_comment = $('.comment-body').text();
$('.comment-body').text(old_comment + '\n' + new_comment);
如果在表的多行中有
.comment body
,并且只想“刷新”其中一行,则需要指定一个id,以便可以精确定位包含单元格的行。例如

<tr id="row1"><td class="comment-body">..comment..</td><tr>

$("#row1").find(".comment-body").html("New Comment Text")
。注释。。
$(“#行1”).find(“.comment body”).html(“新注释文本”)
注意:除了
.html
之外,您还可以使用
.text
来防止用户评论中的html代码被注入您的页面

var old_comment = $('.comment-body').text();
$('.comment-body').text(old_comment + '\n' + new_comment);
我真的不明白你的意思。上面的代码是t