Jquery的Ajax中contentType和dataType的區別

上代碼html

$.ajax({
    type: httpMethod,
    cache:false,
    async:false,
    contentType: "application/json; charset=utf-8",
    dataType: "json",//返回值類型
    url: path+url,
    data:jsonData,
    success: function(data){
        var resultData = '返回碼='+data.status+',響應結果='+data.message+',耗時='+data.tcost;
        layer.msg(resultData,{icon: 1});
    },
    error : function(xhr, ts, et) {
        layer.msg('服務調用失敗!', {icon: 2});
    }
});

 

區分:ajax

contentType: 發送信息至服務器時內容編碼類型,簡單說告訴服務器請求類型的數據chrome

   在調試js時候經過chrome的F12或firefox的firebug查看請求參數時,尤爲請注意headjson

   默認值: "application/x-www-form-urlencoded"服務器

dataType:告訴服務器,我要想什麼類型的數據,除了常見的json、XML,還能夠指定 html、jsonp、script或者textapp

相關文章
相關標籤/搜索