Skip to content

Instantly share code, notes, and snippets.

@kshyju
Created June 23, 2014 18:37
Show Gist options
  • Save kshyju/1de02464cb6b144f792d to your computer and use it in GitHub Desktop.
Save kshyju/1de02464cb6b144f792d to your computer and use it in GitHub Desktop.
Nested ajax callbacks to make sure that we load look up data in all dropdowns before loading the page data.
//What is the alternative of getting rid of the nested callback hell ?
//Load the data for the 3 dropdowns
$http.get('Products/AllProducts/').success(function (data) {
$scope.products = data;
$http.get('Colors/AllColors/').success(function (colordata) {
$scope.colors = colordata;
$http.get('Products/AllSizes/').success(function (sizedata) {
$scope.sizes = sizedata;
// If this is an edit view, Load the saved data from db
if ($("#OrderId").length) {
$http.get('Orders/details?orderId=' + $("#OrderId").val()).success(function (orderData) {
$scope.formulaOperands = $scope.doSomeProcessingWithIds(orderData);;
});
}
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment