ITeye博客

jQuery Ajax 传中文参数出现乱码(传值,乱码)

20444465 · 2012-03-16 09:57 · C# · JQuery · JavaScript · HTML · Web前端 · Markdown

解决方案一:(修改jquery.js) 修改前: ajaxSettings: { url: location.href, global: true, type: "GET", contentType: "application/x-www-form-urlencoded", processData: true, async: true, ..... 修改后: ajaxSettings: { url: location.href, global: true, type: "GET", contentType: "application/x-www-form-urlencoded;charset=UTF-8", processData: true, async: true, ..... 调用的时候: $.ajax({ contentType: "application/x-www-form-urlencoded;charset=UTF-8", ...... 只需要简单的将JQuery的代码加以修改,加上charset=UTF-8就可以了,这样不需要改变改什么web.config或什么在页面中改编码什么的了,也不需要用escapc(str)再在服务端解码。英文怎么传递,中文也怎么传递。

评论(1)

  1. #1 楼 · sfc235300 · 2012-10-25 14:20

    假如我传的一个参数为name=李连杰 后台request.getParameter("name")的值仍然是乱码,怎么回事?

评论功能维护中,当前仅展示历史评论。