//主要将第二个参数设为函数,通过函数获取返回值。
function checkDepart(str,returnFun){
$.ajax({
url: 'listDepart',
method: 'get',
dataType: 'json',
async: false,
success: function (data1) {
for (var i=0; i<data1.data.length; i++){
if (data1.data[i].dept_name == str){
returnFun(false);
return;
}
}
returnFun(true);
return;
}
})
}
//获取returnFun的值,其中data为true或flase
checkDepart(str, function (data) {
console.log(data);
});
如何获取ajax中success函数的返回值
最新推荐文章于 2024-01-05 15:43:51 发布