這裏是第A的JavaScript/AJAX的樣品:如何使用ajax通過網址發佈消息並保持換行符?
var commReq = getXmlHttpRequestObject();
function AddComment(Comment){
if (commReq.readyState == 4 || commReq.readyState == 0){
commReq.open("GET", '/receiveComment.php?com='+Comment+'&' + Math.random(), true);
commReq.onreadystatechange = handleComment;
commReq.send(null);
}
}
現在接收註釋的PHP頁面(receiveComment.php)PAGE B:
$Comment = mysql_real_escape_string(preg_replace("/[^A-Za-z0-9_,[email protected]:'\"\/\n ]/","", $_GET['com']));
mysql_query("INSERT INTO Comments (Comment,Date) VALUES ('$Comment','$Date')");
顯然這些只是樣本裁減,但從2頁。自從我通過ajax存儲評論以來,頁面B從未見過。但我希望能夠存儲用戶可以在textarea框中插入的換行符。任何幫助或建議將不勝感激!
太棒了,這工作!謝謝! – SReca 2011-01-11 20:12:27