CKEditor:ajax提交后出现奇怪的字符
我正在使用 ajax 收集 CKEditor 内容并将其提交到服务器。提交后一看,所有的html标签都是<<和>已转换为其 html 实体。这不是我想要的,因为我显然需要保留 HTML。
我是不是做错了什么?
I am using ajax to gather the CKEditor content and submit it to the server. Once I look at it after it is submitted, all the html tags < and > have been converted to their html entities. This is not what I want, as I obviously need to preserve the HTML.
Is there something I did wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
有几个问题:
我使用 jQuery + validate(表单验证插件)来提交表单。
CKEditor 绑定的文本区域被命名为body。
由于某种奇怪的原因,当我提交表单时,内容根本没有提交。查看 HTML,我发现 CKEditor 没有填充文本区域(不要问我为什么)。
我所做的是在提交之前,手动从 CKEditor 获取数据并将其存储到文本区域中。一行 jquery 就足够了。
然后正常进行表单提交。 jQuery 有一个非常好的数据序列化方法 - 一个名为 serialize() 的函数,我用它来将整个表单的数据转换为字符串。在 PHP 端,该字符串会自动转换为 $_POST 数组的成员。
您应该尝试相同的方法,看看它是否适合您。
如果您仍然遇到困难,请在此处发布您的代码。
干杯,
米^e
A couple of questions:
I use jQuery + validate (form validation plugin) for my form submissions.
The textarea to which CKEditor is bound is named body.
For some weird reason when I submitted the form, the content wasn't being submitted at all. Looking into the HTML I found that the textarea wasn't being populated by CKEditor (don't ask me why).
What I did was to just prior to submission, manually grab the data from CKEditor and stash it into the textarea. A single line of jquery should suffice.
And then proceed with the form submission normally. jQuery has a very good data serialization method - a function called serialize(), which I use to convert the entire form's data into a string. At the PHP end, this string is auto-converted into members of the $_POST array.
You should try the same approach and see if it works for you.
If you're still stuck, post your code here.
Cheers,
m^e
最后我意识到我的服务器没有以 UTF-8 保存数据,即使 ajax 是以这种方式发送的。所以,我解决了这个问题并且数据保存正确。
In the end I realized that my server was not saving the data at UTF-8 even though ajax was sending it this way. So, I fixed that and the data saves correctly.
正确的是在config中设置这个
实体:假
Correct is to set up in config this
entities : false