JQuery ajax url傳值與data傳值的區別


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",
});

image

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);
    }
});

image

image


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM