[英]Getting JavaScript error on asynchronous postback scope function
我在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运行时错误:“错误”未定义
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';
})
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.