var bar = dataService.makeHttpRequest("GET", "/documents/checkfilename/", null,
function (data, status, headers, config) {
// I can see `true` if I alert(data); here
// I want to return the contents of data because
// it's a true/false and would perform tasks based
// on it being true or false.
return data;
});
alert(bar); // this should alert `true` or `false` but is `undefined`
爲什麼警報(bar)總是返回undefined
?我知道data
在上面的函數有true
或false
,我能夠提醒它;但是,我想回報它,只有在事情真的時才做。
的dataService.makeHttpRequest
服務功能如下所示:
dataService.makeHttpRequest = function(requestType, urlString, dataObject, successFunc, errorFunc) {
$http({
method:requestType,
url:$rootScope.serverAddress+urlString,
data:dataObject
})
.success(successFunc)
.error(errorFunc);
};
你逝去的HTTP請求後執行的回調,所以酒吧的功能只是返回'makeHttpRequest',它不返回任何東西,所以你得到'undefined'。 – GillesC