CKEditor:ajax提交后出现奇怪的字符

发布于 2024-08-09 01:32:20 字数 128 浏览 6 评论 0原文

我正在使用 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 技术交流群。

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

发布评论

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

评论(3

寄人书 2024-08-16 01:32:20

有几个问题:

  1. 您使用哪个 AJAX 库?
  2. 您使用什么方法从 CKEditor 获取内容?

我使用 jQuery + validate(表单验证插件)来提交表单。

CKEditor 绑定的文本区域被命名为body

由于某种奇怪的原因,当我提交表单时,内容根本没有提交。查看 HTML,我发现 CKEditor 没有填充文本区域(不要问我为什么)。

我所做的是在提交之前,手动从 CKEditor 获取数据并将其存储到文本区域中。一行 jquery 就足够了。

$( '#body' ).val( CKEDITOR.instances.body.getData() );

然后正常进行表单提交。 jQuery 有一个非常好的数据序列化方法 - 一个名为 serialize() 的函数,我用它来将整个表单的数据转换为字符串。在 PHP 端,该字符串会自动转换为 $_POST 数组的成员。

您应该尝试相同的方法,看看它是否适合您。

如果您仍然遇到困难,请在此处发布您的代码。

干杯,
米^e

A couple of questions:

  1. Which AJAX library are you using?
  2. What method are you using to fetch the content from CKEditor?

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.

$( '#body' ).val( CKEDITOR.instances.body.getData() );

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

赠我空喜 2024-08-16 01:32:20

最后我意识到我的服务器没有以 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.

若有似无的小暗淡 2024-08-16 01:32:20

正确的是在config中设置这个
实体:假

Correct is to set up in config this
entities : false

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