0

I am trying to use normal jQuery Ajax in anuglarjs .

$.ajax({
   type: "POST",
   url: window.apirooturl + "/logger", 
   contentType: "application/json",
   data: angular.toJson({
       url: $window.location.href,
       message: errorMessage,
       type: "exception",
       stackTrace: stackTrace,
       cause: ( cause || "")
   })
});

But i am getting an error

Below two messages appears in the firbug

  1. $ is not defined
  2. Error: [$rootScope:inprog] $digest already in progress

Do we need to configure something to use normal jquery function in anagularjs? I tried to look on Google but could not get a answer

More information : I am trying to send client side error to the server side and trying to implement a global exception handler as suggested in this post . http://www.bennadel.com/blog/2542-logging-client-side-errors-with-angularjs-and-stacktrace-js.htm

Atul Rai
  • 140
  • 10
  • 1
    Have a look to this question http://stackoverflow.com/questions/12131659/from-jquery-ajax-to-angular-http – V31 Jul 14 '14 at 09:00
  • Why are you not using [$http](https://docs.angularjs.org/api/ng/service/$http)? – Satpal Jul 14 '14 at 09:03
  • I know $http and its is used in project also .But for a specific requirement "logging client side errors to the server" .I am trying to implement as sugguested on this blog http://engineering.talis.com/articles/client-side-error-logging/ – Atul Rai Jul 14 '14 at 09:18

2 Answers2

1

You are not supposed to use $.ajax in angular you need to use $http request

for example, this is ho you should use post:

$http({
    url: "http://example.com",
    method: "POST",
    data: {"a":"b"}
}).success(function(data, status, headers, config) {
    $scope.data = data;
}).error(function(data, status, headers, config) {
    $scope.status = status;
});

please see more at : https://docs.angularjs.org/api/ng/service/$http

Muhammad Reda
  • 26,379
  • 14
  • 93
  • 105
Liad Livnat
  • 7,435
  • 16
  • 60
  • 98
  • Hi Liad ,There is a circular dependency between the $exceptionHandler and $http thats why i am trying to avoid the use of $http thx – Atul Rai Jul 14 '14 at 09:42
0

1) If you reference full jQuery library, Angular should use it instead of it's own. Do you reference it before angular.js file?

2) Wrap your code with $timeout to prevent error '$digest already in progress'

Jan Barta
  • 450
  • 2
  • 8