jQuery中文乱码解决方案

jQuery遇到中文乱码问题,其实就是因为contentType没有指定编码,
只需在jQuery.js中搜索
'contentType'
然后在application/x-www-form-urlencoded后面加上
; charset=UTF-8
最终变成
contentType:"application/x-www-form-urlencoded; charset=UTF-8"
问题搞定。

另外,也可在具体调用时指定

contentType:"application/x-www-form-urlencoded; charset=UTF-8"参数,如:
$.ajax({
                type: "post",
                url: "/my/login.aspx",
                data: $('#loginform').serialize(),
                dataType: "json",
                contentType:"application/x-www-form-urlencoded; charset=UTF-8",
                success: function (json) {
                    if (json.statusCode == 200) {
                        window.location.reload();
                    } else {
                        $("#J_logininfo").attr("class", "fail").html(json.message);
                    }
                },
                beforeSend: function (o) {
                    $("#J_logininfo").attr("class", "focus").html("登录中...");
                }
            });
 
原文地址:https://www.cnblogs.com/leadwit/p/1971630.html