异步请使用Promise
function getNewDate(flyNum)
{
return new Promise(function(resolve,reject)
{
$.ajax(
{
url: '',
type: 'GET',
dataType: 'json',
async: true,
data:
{
param1: flyNum
},
})
.done(function(res)
{
var thisDate = res.data.date; //需要返回thisDate
resolve(thisDate);
})
.fail(function(err)
{
//console.log("error");
reject(err);
})
.always(function()
{
});
});
}
getNewDate(123).then(function(resolveData)
{
//code....
console.log('resolveData',resolveData);
},function(rejectData)
{
console.log('rejectData',rejectData);
});