A. Noak
A. Noak

Reputation: 13

Cannot call method 'then' of undefined - $.ajax

I use $.ajax in my angularjs controller to save an order. After I updated to AngularJS 1.2.2 i get the error TypeError: Cannot call method 'then' of undefined when $.ajax is called. I cannot find any information about that anything has changed. Am I doing something wrong? Here is my code for the ajax call:

$scope.saveOrder = function () {

  $.ajax({
     type: 'POST',
     url: $scope.saveOrderUrl,
     data: $scope.order,
     async: false,
     dataType: 'json',
     success: function (result) {
         $scope.order = result;
         $scope.isNewOrder = false;
         if ($scope.order.OrderId === 0) {
             alert("No order id was returned from the server. The order will not be opened in view mode.");
             window.location.href = appUrl + "/Order/Index/" + $scope.patientId;
         } else {
             window.location.href = appUrl + "/Order/Details/?personId=" + $scope.patientId + "&orderId=" + $scope.order.OrderId;
         }
     },
     error: function (xhr, status, error) {
         alert("Error when saving order. Status: " + status);
     }
 });

}

Upvotes: 0

Views: 602

Answers (1)

Friso
Friso

Reputation: 1110

$.ajax is jQuery's (or Angular's jQuery lite implementation) ajax method. To get Angular's Promises you need to use $http (note the absense of . after $)

Upvotes: 1

Related Questions