How to load the comment list through ajax
唐彡公子
唐彡公子 2018-08-16 17:24:40
0
3
1327

The comment information is loaded when you first enter the details page, but every time you post a comment, if you do not refresh the page, the comment content cannot be loaded. What should I do through ajax?

唐彡公子
唐彡公子

reply all(2)
唐彡公子

It has been implemented, let me talk about the idea, teacher, see if this is appropriate

1. When loading the details page, follow the background query and template assignment method, and implement the first load through volist in the foreground

2 , post a comment after entering the details page, submit a new comment through ajax at the front desk, execute the new comment in the background and obtain the data from multiple tables after success and return it to the template

3. After the front desk receives the returned data, it passes through a for loop Traverse the data and load it into the comment list

Front-end code:

if (datas.status == 1) {
$('#result').text(datas.message );
var str = "";
$("#comm").html("");
for (var i = 0; i < datas.data.length; i++) {
        str = '<div style=\"width: 95%\">' +
                '<p>'+ datas.data[i].name +'   ' + timestampToTime(datas.data[i].create_time) + '</p>' +
'<div style=\"min-height: 50px;\">' + datas.data[i] .content + '</div>' +
'<hr style=\"margin: 0\">' +
'</div>';
'<hr style=\"margin: 0\">' +
").append(str);
}
$("#comment")[0].reset();
} else {
$('#result').text(datas .message);

}###
Dancy

An interface for publishing comments and an interface for obtaining comment information. After each comment is published, the latest comment content is obtained through ajax again

  • reply Thank you for your answer. Is there any problem with my own implementation? Please help me.
    唐彡公子 author 2018-08-18 10:07:30
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template