用textarea提交的jQuery序列化错误

我正在使用此function,在后台提交表单,并附带自定义消息。 除了textarea字段外,它完美地运行。 我已经读过序列化函数与ex有问题。 换行符。

$(function() { $("#comment_form").validate({ submitHandler: function(form) { $.post('/u/r/l/', $("#comment_form").serialize(), function(data) { $('#comment_container').html(data); }); } }); 

textarea是一个标记! 编辑区。

如上所述: http : //api.jquery.com/serialize/#comment-67394779

 function keepLB (str) { var reg=new RegExp("(%0A)", "g"); return str.replace(reg,"%0D$1"); } $(function() { $("#comment_form").validate({ submitHandler: function(form) { $.post('/u/r/l/', keepLB($("#comment_form").formSerialize()), function(data) { $('#comment_container').html(data); }); } }); 

如果它不起作用,手动urlencode textarea数据:

 $(function() { $("#comment_form").validate({ submitHandler: function(form) { $.post('/u/r/l/', "textareadata="+escape($("#mytextarea").value), function(data) { $('#comment_container').html(data); }); } }); 

如果你还想发送其他表单内容(注意:不要在这里给textarea一个“名字”,只是一个id!):

 $(function() { $("#comment_form").validate({ submitHandler: function(form) { $.post('/u/r/l/', $("#comment_form").formSerialize()+"&textareadata="+escape($("#mytextarea").value), function(data) { $('#comment_container').html(data); }); } }); 

一个想法(如果jQuery序列化的标准用法不起作用)是标记代码采用该textarea并做一些奇特的事情,以便它甚至不再像textarea那样。 Markitup API中是否有某种方法可以检索数据?

这里main_post_txt是您正在使用的html文本区域元素的id,在jquery中,您可以通过使用它轻松获得其值

 var post_text = $("#main_post_txt").serialize();