提交后显示评论
Show comment after submit
在我的wordpress网站上,我有一个标准的评论提交表单。我在其中添加了一个脚本(ajax),因此我不必重新加载页面即可提交评论。一切正常,但是如何在不刷新页面的情况下显示提交的评论?
我的代码:
jQuery('document').ready(function($){
var commentform=$('form#commentform');
commentform.prepend('<div id="wdpajax-info" ></div>');
var infodiv=$('#wdpajax-info');
commentform.validate({
submitHandler: function(form){
var formdata=commentform.serialize();
infodiv.html('<p>Proszę czekać...</p>');
var formurl=commentform.attr('action');
$.ajax({
type: 'post',
url: formurl,
data: formdata,
error: function(XMLHttpRequest, textStatus, errorThrown){
infodiv.html('<p class="wdpajax-error" >Sprawdź wszystkie pola!</p>');
},
success: function(data, textStatus, html){
$("ul.commentlist").append(formdata);
$("ul.commentlist li:last").fadeIn("slow");
if(data=="success")
infodiv.html('<p class="wdpajax-success" >Dzięki, komentarz został dodany!</p>');
else
infodiv.html('<p class="wdpajax-error" >Błąd</p>');
commentform.find('textarea[name=comment]').val('');
}
});
}
});
});
我建议刷新页面,以便用户可以看到评论确实已保存在服务器端。如果您仍然想在不刷新页面的情况下执行此操作,则应添加带有注释的新div。类似于这样的东西:
success: function(data, textStatus, html){
$("ul.commentlist").append(formdata);
$("ul.commentlist li:last").fadeIn("slow");
if(data=="success") {
infodiv.html('<p class="wdpajax-success" >Dzięki, komentarz został dodany!</p>');
// you should inicialize commentdiv with the selector of the part of the page you want to show the comment
commentdiv.html('<p class="comment">'+formdata+'</p>');
}
相关文章:
- yammer在手机上嵌入评论不显示回复选项
- React/Node应用程序中的Facebook评论插件.js仅在刷新时显示
- 显示最新评论,然后向上滚动以查看较早的评论
- 提交后显示评论
- 删除在 Blogger JS 小部件上显示的评论编号
- 你如何只显示一定数量的Facebook评论,并使用Facebook API隐藏其余的评论
- 如果网页没有显示评论/信息框的Ajax代码't负载
- 是否可以随着时间的推移显示检索到的评论
- 使用本地存储允许某人发表评论,然后显示保存的评论
- 通过ajax显示评论的全文或短文本
- 显示带有所述点击事件的评论表单
- Facebook社交插件评论不显示时直接链接到
- 不能在jquery窗口中显示评论
- 清除表单和显示新的评论jquery php
- 如何禁用Facebook评论显示在博客主页和类别页面
- 只显示评论的数量
- Facebook评论插件在AngularJS中不显示
- 点击显示评论后加载Facebook评论
- 如果WordPress评论日期低于2014年4月,如何显示p标签
- 需要javascript根据下拉选择在表单上显示特定的评论框