$.ajax({
url:'http://xxx.test',
type: 'Post',
data: JSON.stringify(model),
dataType: 'json',
contentType : "application/json",
success: function (data) {
console.log(data);
//根據回調信息提示
if (data[0].result == 'success') {
layer.msg('獲取成功');
} else {
layer.msg(data[0].message);
}
}
});
今天一個同事遇到了一個500錯誤,程序如上所示,最開始以為數據太多,數據調少后,替換掉%等特殊字符不報,,解決辦法有兩種
1、如果使用JSON.stringify,一定要加contentType : "application/json"
2、或者不用JSON.stringfy,去掉contentType:"application/json"
在網上看到的一個講解
http://stackoverflow.com/questions/11269622/asp-net-jquery-ajax-json-simple-example-of-exchanging-data

