如果我发布评论,如“hello there dog”它的效果很好,但如果有任何特殊字符,如“或”,评论已成功发布到数据库,但jQuery的代码没有任何提示显示在列表中的注释jQuery,发表评论的评论是行不通的,否则它的效果很好
感谢
function feedbacksubmit() {
// Show the Ajax Loader
$("#ajaxloader").css("display","inline");
var textsubmitted = $("#feedbackinput").val();
if (textsubmitted.length < 5) {
alert("Don't forget to write something!");
// Hide the Ajax Loader
$("#ajaxloader").css("display","none");
}
else {
$.post("/feedback/ajax/insert/", {feedback: textsubmitted},
function(data) {
// Place the comment in the top of the list
$('<li></li>').prependTo("#comment-list").hide().prepend(data.commenttext2insert).fadeIn('slow');
// Hide the Ajax Loader
$("#ajaxloader").css("display","none");
// Clear out the textarea
$("#feedbackinput").val('');
}, "json");
}
}
这里是不是与上面的jQuery代码工作的例子回应:。
{"returnmessage":"The Ajax operation was successful.","returncode":"0","commenttext2insert":"\n\t<div class=\"comment-header\">\n\t\t<span class=\"comment-avatar\">\n\t\t\t<a href=\"\">\n\t\t\t\t\n\t\t\t\t\t<img src=\"/_images/users/photos//17941/nobosh.jpg\" />\t\t\t\t\t\t\t\n\t\t\t\t\n\t\t\t</a>\n\t\t</span>\n\t\t<span class=\"comment-author\">\n\t\t\t<a href=\"\">\n\t\t\t\t<b>BOB Man</b>\n\t\t\t</a>\n\t\t</span>\n\t\t<span class=\"comment-timestamp\">just now</span>\n\t</div>\n\t<div class=\"comment-body\">\n\t\t<p>12wsa\'</p>\n\t</div>\n"}
您使用哪种服务器端语言?此外,您是否考虑过返回* real * JSON对象并在jQuery中构建HTML,而不是使用服务器准备的HTML返回JSON? – BalusC 2010-02-21 00:20:52
我正在使用Coldfusion ...最好不要使用服务器准备的HTML?为什么? – AnApprentice 2010-02-21 00:26:51
JSON非常棒,但是如果您要返回HTML,最好将它作为HTML而不是JSON返回,以减少服务器和客户端所需的不必要的处理,并且代码会更干净。或者像BalusC提到的那样,您可以转到其他路由并返回JSON并在客户端构建HTML。所有三个技术上都可行,但HTML over JSON可能是最难处理的问题。 – 2010-02-21 16:34:42