POST或GET请求某接口时,前端js的处理方式:
(一)GET
$.ajax({
type: "get",
data:{
"startTime":startTime,
"endTime":endTime,
"percentStart":percentStart,
"percentEnd":percentEnd
},
url: domainName+"/scn/view/getCreditInfo",
dataType: "json",
success: function (res) {
if (res.code == '200') {
}
}
});
(二)POST
与GET请求方式有两点不同的地方:
1、在ajax中,需要指定contentType;
2、在指定data时,需要将传入的参数转为json,可使用JSON.stringify()方法实现。
$.ajax({
type: "post",
contentType: "application/json; charset=utf-8",
data: JSON.stringify({
"startTime":startTime,
"endTime":endTime,
"percentStart":percentStart,
"percentEnd":percentEnd
}),
url: domainName+"/scn/view/queryReportShipNum",
dataType: "json",
success: function (res) {
if (res.code == '200') {
}
}
});