AJAX/JQUERY 特殊字符的奇怪行为

发布于 2024-10-05 13:31:27 字数 621 浏览 0 评论 0原文

您好,我正在开发一个简单的应用程序,用户只需单击“编辑并保存”即可更改数据库中的内容,而无需刷新页面。这是通过 Jquery、AJAX POST 和 CKeditor(检索内容的文本区域)完成的。

如果我在 CKeditor 文本区域中写入“您好,这是一个测试!”我明白了

<p>Hello this is  a text</p>

,一切正常。如果我写“你好,这是一个很酷的测试,不是吗?”我明白了:

<p> Hello this is a cool test, isn&#39;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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

小伙你站住 2024-10-12 13:31:27

您到底是如何将数据放在一起并发布的?您需要使用 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文