JQuery ajax url传值与data传值的区别

时间:2023-03-08 20:16:24

url传中文,乱码,即便charset为 UTF-8,

$.ajax({
    type: "POST",
    cache: false,
    url: "/ProductTypeAndCat/AddType?typeName=" + typeName,
    contentType: "application/x-www-form-urlencoded; charset=UTF-8",
    datatype: "JSON",
});

JQuery ajax url传值与data传值的区别

data传中文,正确。

$.ajax({
    type: "POST",
    cache: false,
    url: "/ProductTypeAndCat/AddType",
    data: {typeName:typeName},
    contentType: "application/x-www-form-urlencoded; charset=UTF-8",
    datatype: "JSON",
    success: function (data) {
        if (data.F == 0) {
            alert("添加陈功");
            location.href = "/Admin/ProductType";
        }
        else {
            alert(data.M);
        }
    },
    error: function (xhr, status, error) {
        alert(error);
    }
});

JQuery ajax url传值与data传值的区别

JQuery ajax url传值与data传值的区别