html调用后台接口(ajax)
原创1.请注意此处this指向
//查询列表
queryData: function() {
console.log("查询")
let that = this
$.ajax({
type: "POST",
url: /maturity/getByOfficeId?year= + this.ruleForm.year + &officeId= + comId,
dataType: "json",
async: false,
success: function(res) {
console.log("result111111", res)
let getData = res.data
that.addForm = getData
},
error: function (xhr, status, error, result, response) {
var tip = xhr.responseJSON ? xhr.responseJSON.message : (val == save ? (that.dialogTitle == "创建" ? 创建失败 : 修改失败) : 提交失败)
that.$message.error(tip);
}
});
},
2.application/json
contentType通常默认application/x-www-form-urlencoded,这次post请求背景已更改application/json
data: JSON.stringify(this.addForm),
data数据需要更改
$.ajax({
type: "POST",
url: /maturity/submit,
dataType: "json",
data: JSON.stringify(this.addForm),
contentType: application/json;charset=UTF-8,
// contentType:application/x-www-form-urlencoded,
async: false,
success: function(res) {
console.log("保存提交", res)
}
});
版权声明
所有资源都来源于爬虫采集,如有侵权请联系我们,我们将立即删除