Solving the garbled problem of jquery after form serialize

Source: Internet
Author: User

通过看jQuery源码可以知道,serialize方法是通过encodeURIComponent编码的,所以解决乱码的最笨方法:  1、重新分解序列化后的值  2、把分解的值重新decodeURIComponent回来  3、再重新用escape编码  4、重新拼接  function serialize(objs)      var parmString = $(objs).serialize();      var parmArray = parmString.split( "&" );      var parmStringNew= ""     $.each(parmArray, function (index,data){          var li_pos = data.indexOf( "=" );           if (li_pos >0){              var name = data.substring(0,li_pos);              var value = escape(decodeURIComponent(data.substr(li_pos+1)));              var parm = name+ "=" +value;              parmStringNew = parmStringNew== "" ? parm : parmStringNew + ‘&‘ + parm;              });      return parmStringNew;  }

Solving the garbled problem of jquery after form serialize

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.