从ajax post()返回值的方法有多种,以下是其中几种常见的方式:
$.post(url, data, function(response) {
// 处理返回的数据
console.log(response);
});
function postData(url, data) {
return new Promise(function(resolve, reject) {
$.post(url, data, function(response) {
resolve(response);
}).fail(function(error) {
reject(error);
});
});
}
// 调用方式
postData(url, data)
.then(function(response) {
// 处理返回的数据
console.log(response);
})
.catch(function(error) {
// 处理错误
console.error(error);
});
async function postData(url, data) {
try {
const response = await $.post(url, data);
// 处理返回的数据
console.log(response);
} catch (error) {
// 处理错误
console.error(error);
}
}
// 调用方式
postData(url, data);
以上是几种常见的从ajax post()返回值的方法,根据具体情况选择适合的方式进行处理。
云+社区沙龙online [技术应变力]
腾讯位置服务技术沙龙
云+社区技术沙龙[第10期]
北极星训练营
高校公开课
停课不停学 腾讯教育在行动第二期
《民航智见》线上会议
云+社区技术沙龙[第15期]
Techo Youth
领取专属 10元无门槛券
手把手带您无忧上云