AJAX/JQUERY 特殊字符的奇怪行为
您好,我正在开发一个简单的应用程序,用户只需单击“编辑并保存”即可更改数据库中的内容,而无需刷新页面。这是通过 Jquery、AJAX POST 和 CKeditor(检索内容的文本区域)完成的。
如果我在 CKeditor 文本区域中写入“您好,这是一个测试!”我明白了
<p>Hello this is a text</p>
,一切正常。如果我写“你好,这是一个很酷的测试,不是吗?”我明白了:
<p> Hello this is a cool test, isn't it?</p>
应该如此。这也是通过 POST/JQuery/AJAX 发送的(通过 FireBug 验证),但奇怪的是,在 PHP 脚本中,如果我回显传递的值,就会收到字符串,
<p> Hello this is a cool test, isn
这怎么可能? 谢谢
编辑找到的解决方案: 我必须在ajax发送的数据中添加encodeURIComponent(content)
Hello I'm developing a simple application where the user can change a content in a database by simply clicking "edit and save" without page refreshes. This is done with Jquery, AJAX POST and CKeditor (the textarea from where the content is retrieved)
If I write in CKeditor textarea "Hello this is a test!" I get
<p>Hello this is a text</p>
and everything works fine. If I write "Hello this is a cool test, isn't it?" I get:
<p> Hello this is a cool test, isn't it?</p>
as it should be. This is ALSO sent via POST/JQuery/AJAX (verified via FireBug) but strangely in the PHP script that receivices the string if I echo the value passed I get
<p> Hello this is a cool test, isn
How is that possible?
Thank you
EDIT SOLUTION FOUND:
I had to add encodeURIComponent(content)
in the ajax sent data
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您到底是如何将数据放在一起并发布的?您需要使用
encodeURIComponent
,但通常 JQuery 应该为您做这件事。How exactly are you putting the data together and POSTing it? You need to use
encodeURIComponent
, however normally JQuery should be doing that for you.