开发者

jQuery serialize problem

On my website I have a CKEDITOR to publish content. I have build an automatic save function when you switch pages that looks like this:

var oEditor = CKEDITOR.instances.text;              
var content = oEditor.getData();
$('#form #text').html(content);

$.post("news/save/" + id + "/" + page, $("#form").serialize());

This gets the current content of the editor, places it in the textarea (it did not always do that automatically apparently). Then serializes the entire form and posts it to my website's save page.

This is works except for when I put youtube code inside the editor. Printing out the following works without any problems (after the content was set):

alert($('#form #text').html());

This would just prints the actual content with the youtube code. But when the .serialize() functions is called the content gets empty.

alert($('#form #text').serialize());

This would just print: "text=%0A".

Can anybody help me fix this probl开发者_如何学Pythonem or suggest another way to post the form's content to the save page?

Thank you.


Is #text is a textarea? if it is then you should probably using val() method to set the value instead of html(), because val() should be used to set/get form element's value.


You should call editor's synchronize procedure, that synchronizes editor contents with the value of the textarea. After that, the value will be available for serialization as well.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜