使用 Javascript 处理从数据库到 HTML 的 NL2BR
我似乎在显示 HTML 时遇到困难。哈哈,我来解释一下。
我有 1 个“评论”模板文件...它告诉 html 中的内容去哪里等。添加、更新和选择任何“评论”时
IE:
<div class='comment'>
<div>{$name}</div>
<div>{$comment}</div>
</div>
所以在我的评论中,我需要从数据库中提取评论,其中包括, \n
所以我会这样。
$comment = nl2br($comment);
<div class='comment'>
<div>{$name}</div>
<div>{$comment}</div>
</div>
这确实有效...但是当我通过 jQuery 进行更新时,我使用
$("#"+ target +"").replaceWith(responseText);
,responseText 包括所有 HTML...但出于某种原因,它仍然包括 \n...而不是
我不知道知道这是否是 Javascript 的限制或渲染问题。只是不知道还能去哪里......有什么想法吗?
I am having difficulty with displaying HTML it seems. haha, let me explain.
I have 1 template file for "comments"... and it tells things where to go and such in the html. When Adding, Updating and Selecting any of the "comments"
IE:
<div class='comment'>
<div>{$name}</div>
<div>{$comment}</div>
</div>
So within my comment I need to pull the COMMENT from the database which includes, \n
So I go like this.
$comment = nl2br($comment);
<div class='comment'>
<div>{$name}</div>
<div>{$comment}</div>
</div>
And this does work... But when I do an UPDATE via jQuery I use,
$("#"+ target +"").replaceWith(responseText);
And the responseText includes all HTML... but some reason, it still is including the \n... and not
I don't know if this is a limitation with Javascript, or rendering issues. Just not sure where else to go here...Any thoughts?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 php 文件中,您使用 jQuery 获取注释,在回显数据之前尝试执行以下操作
In the php file you are getting the comments with using jQuery try doing the following before echoing the data back
嗯,这有点奇怪,有一些问题我没有完全测试,很抱歉可能没有澄清。但是 mysql_real_escape_string() 导致 \n 存储在数据库中出现问题。
我正在考虑使用这个函数。在 php.net 网站上找到
Well this was a tad strange, there was some issues that I didn't fully test and sorry for maybe not clarifying. But mysql_real_escape_string() was causing issues with the \n being stored in the database.
There for I am looking at using this function instead. Found on php.net's website