我正在尝试在 anuglarjs 中使用普通的 jQuery Ajax 。
$.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 || "")
})
});
但我收到错误
firbug 中出现以下两条消息
- $ 未定义
- 错误:[$rootScope:inprog] $digest 已在进行中
我们需要配置一些东西才能在anagularjs中使用普通的jquery功能吗? 我尝试在 Google 上查找,但找不到答案
更多信息: 我正在尝试将客户端错误发送到服务器端,并尝试按照本文中的建议实现全局异常处理程序。 http://www.bennadel.com/blog/2542-logging-client-side-errors-with-angularjs-and-stacktrace-js.htm
最佳答案
你不应该在 Angular 中使用$.ajax,你需要使用$http请求
例如,这是您应该使用 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;
});
关于javascript - 如何在 angularjs 中使用 Jquery $.Ajax,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24732870/