這裏我打電話fetchbookAllNew()
方法從fetchBooks()
但與此ajax加載程序不能正常工作。當我想要fetchBooks
被稱爲ajax加載器時,我應該顯示,直到所有的數據,我將獲得.done
函數。如何從多個Ajax調用中獲取數據?
$scope.fetchBooks = function(){
$(".loader").show();
$.when(
fetchbookAllNew("all"),
fetchbookAllNew("epub"),
fetchbookAllNew("collection"),
fetchbookAllNew("video"),
).done(function(publishedAll, publishedEpub, publishedColl,publishedVideo){
$scope.allkitabooBooks = publishedAll;
$scope.allEpubBooks =publishedEpub;
$scope.allcollectionbooks = publishedColl;
$scope.allvideosbooks = publishedVideo;
$(".loader").fadeOut("slow");
});
};
var fetchbookAllNew = function(status){
var books = undefined;
$.ajax({
url:'/booksList', // Dynamically uploads the files which is chosen.
type: 'GET',
headers : {
'usertoken' : $rootScope.userDetails.userToken,
'status':status
},
cache: false,
async: false,
processData: false, // Don't process the files
contentType:'application/json', // Setting content type to "application/octet-stream"/"undefined" as jQuery will tell the server its not query string.
success: function (data) {
books=data;
},
error: function (data) {
}
});
return books;
};
你需要'返回$ .ajax',而不是響應。 – Liam
我需要每個請求的響應來顯示數據根據狀態 –
也rejve ajax:false。這是錯誤的解決方案。所以你在這裏至少有三個不同的問題。 – Liam