用ajax提交到後臺,在與後臺進行數據傳輸時報了Unsupported media type-415錯誤,查了後發現Content-Type未設置,contentType 的默認是application/x-www-form-urlencoded.後端對此設置的爲application/json,so設置上就可以了,可參考如下代碼:
$.ajax({
type:
'POST'
,
url: url,
dataType:
'json'
,
contentType:
"application/json"
,
data: JSON.stringify(setData),
success:
function
(data){
alert(
'數據加載成功'
);
},
error:
function
(xhr, type){
alert(
'數據加載失敗'
);
}
});