0

我在 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 运行时错误:“错误”未定义

4

1 回答 1

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';
        })
    }
}
于 2013-08-13T05:35:52.143 回答