如果我發佈評論,如「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