jQuery serialize error with textarea filed

本小妞迷上赌 提交于 2019-12-01 17:48:40

As stated here: 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);
    });
  }
});

If it doesn't work, manually urlencode the textarea data:

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

And if you also want to send other form contents (note: don't give the textarea a "name" here, just an 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);
    });
  }
});

One thought (if standard usage of jQuery serialize isn't working) is that the markitup code is taking that textarea and do something fancy with it so that it doesn't even act like a textarea anymore. Is there some way in Markitup API to retrieve the data perhaps?

Mahendra Tyagi

Here main_post_txt is the id of html text area element which you are using and in jquery you can get easily its value by using

var post_text = $("#main_post_txt").serialize();  
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!