我在angular.min.js上报告了以下错误
0x800a1391 - JavaScript运行时错误:'错误'未定义
使用以下代码:
javascipt的:
function Sucess()
{
//close
}
function Save()
{
var e = document.getElementById('FormDiv');
scope = angular.element(e).scope();
scope.Apply(Sucess)
}
我的角度范围功能:
function RolesCtrl($scope, $http, $location)
{
$scope.Apply = function (CallBackSucess) {
var userId = getQSP('uid', decode(document.URL));
$http({
method: 'POST', url: 'MultiRole.aspx/Apply',
data: {}
}).
success(function (data, status, headers, config) {
// this callback will be called asynchronously
CallBackSucess();
$scope.f = data.d;
}).
error(function (data, status, headers, config) {
// called asynchronously if an error occurs
// or server returns response with an error status.
$scope.name = 'error';
})
}
}
在发出导致错误的CallBackSucess()
调用之前,一切似乎都正常工作:
0x800a1391 - JavaScript运行时错误:'错误'未定义
答案 0 :(得分:0)
CallBackSucess
参数传递给.Apply()
方法。它不会传递给.success()
方法 - 它们是具有单独范围的链式方法。因此,在.success()
回调函数中,当您尝试调用它时未定义CallbackSucess()
,从而导致错误。
另外,你真的想拼错Sucess
吗?
仅供参考,我必须像这样格式化你的代码才能看到实际发生的事情:
function RolesCtrl($scope, $http, $location) {
$scope.Apply = function (CallBackSucess) {
var userId = getQSP('uid', decode(document.URL));
$http({
method: 'POST',
url: 'MultiRole.aspx/Apply',
data: {}
}).success(function (data, status, headers, config) {
// this callback will be called asynchronously
CallBackSucess();
$scope.f = data.d;
}).error(function (data, status, headers, config) {
// called asynchronously if an error occurs
// or server returns response with an error status.
$scope.name = 'error';
})
}
}