TypeError:回调不是函数 [英] TypeError : callback is not a function
问题描述
仅当我尝试添加新的回调函数时,我才能获得回调函数参数erreur = TypeError:回调不是函数在services.js:72上,我尝试移动evrything时,我试图添加对该函数的引用,这很好,这是在service.js上的代码,希望您能对我有所帮助.
.factory('Payement', function ($http, $ionicLoading) {
return {
saveContratEtudant: function (_nb_piece1,_nb_piece2,_shortadresse,_govClt,_villeClt,_localiteClt,_voieClt,_cod_logem,_adresse_logem,_govLogem,_gelgLogem, _dateDel,_dateEffet,_dateExp,_nomAssure, _prenomAssure ,_piece2,_numDocument,_typeContrat,_natureContrat,_piece1,_dateNais,_email,_phone,_IdTrans,_reference,_numDocuemnt,_codePostal,_adresse,_typedocu,_sexeClt,_tarif,_frais ,_tva, _tcc, callback) {
$http({
method: 'POST',
url:SAVE_ETUDIANT,
timeout: 10000,
data: {
nb_piece1:_nb_piece1,
nb_piece2:_nb_piece2,
shortadresse:_shortadresse,
govClt:_govClt,
villeClt:_villeClt,
localiteClt:_localiteClt,
voieClt:_voieClt,
cod_logem:_cod_logem,
adresse_logem:_adresse_logem,
govLogem:_govLogem,
gelgLogem:_gelgLogem,
dateDelivra:_dateDel,
dateEffet:_dateEffet,
dateExp:_dateExp,
nomAssure:_nomAssure,
prenomAssure:_prenomAssure,
piece2:_piece2,
numDocument:_numDocument,
typeContrat:_typeContrat,
natureContrat:_natureContrat,
piece1:_piece1,
dateNais:_dateNais,
email:_email,
phone:_phone,
IdTrans: _IdTrans,
reference:_reference
numDocuemnt:_numDocuemnt,
codePostal:_codePostal,
adresse:_adresse,
typedocu:_typedocu,
sexeClt:_sexeClt,
//nbr_piece: ,
tarif : _tarif ,
frais : _frais,
tva :_tva,
tcc :_tcc,
//reference :_reference
},
}).then(function (response) {
callback(response);
// $ionicLoading.hide();
console.log("ajout ");
});
}
};
})
这是我在controller.js上的代码,我最近尝试添加对BD的引用,因此在我的控制器中设置了var ref并在控制台中获得了var show.
sendbtn.addEventListener('click', function () {
Payement.saveContratEtudant($scope.nb_piece1,$scope.nb_piece2,$scope.shortadresse,$scope.govClt,$scope.villeClt,localiteClt,$scope.voieClt,$scope.cod_logem,$scope.adresse_logem,$scope.govLogem,$scope.gelgLogem,$scope.dateDelivra, $scope.dateEffet, $scope.dateExp, $scope.nomAssure,$scope.prenomAssure,$scope.piece2,$scope.numDocument,$scope.typeContrat,$scope.natureContrat,$scope.piece1, $scope.dateNais,$scope.email,$scope.phone, $scope.IdTrans,$scope.reference, $scope.numDocuemnt, $scope.codePostal, $scope.adresse,$scope.typedocu,$scope.sexeClt,$scope.tarif,$scope.frais,$scope.tva,$scope.tcc ,function (data) {
console.log("test saveContrat")
//console.log("date:",date)
if (data.data.state_code == 200){
$scope.local_ = data;
console.log($scope.local_.data.data);
$state.go('map')
} else {
$ionicPopup.alert({
title: "Alert",
template: data.data.message
});
}
});
这是确切的错误 TypeError:回调不是函数
this is the exact erro TypeError: callback is not a function
at services.js:72
at processQueue (ionic.bundle.js:29132)
at ionic.bundle.js:29148
at Scope.$eval (ionic.bundle.js:30400)
at Scope.$digest (ionic.bundle.js:30216)
at Scope.$apply (ionic.bundle.js:30508)
at done (ionic.bundle.js:24829)
at completeRequest (ionic.bundle.js:25027)
at XMLHttpRequest.requestLoaded (ionic.bundle.js:24968)
推荐答案
这只是意味着在此部分代码中:
It simply means that in this portion of code :
.then(function (response) {
callback(response); // <- HERE
// $ionicLoading.hide();
console.log("ajout ");
});
您正在调用名为回调"的函数.但这还没有定义.可能是因为在此函数的最后一个参数中没有任何参数作为参数传递:
You are calling the function named "callback". But it's not defined. Probably because nothing is passed as param in the last param of this function :
saveContratEtudant: function (_nb_piece1,_nb_piece2,_shortadresse,_govClt,_villeClt,_localiteClt,_voieClt,_cod_logem,_adresse_logem,_govLogem,_gelgLogem, _dateDel,_dateEffet,_dateExp,_nomAssure, _prenomAssure ,_piece2,_numDocument,_typeContrat,_natureContrat,_piece1,_dateNais,_email,_phone,_IdTrans,_reference,_numDocuemnt,_codePostal,_adresse,_typedocu,_sexeClt,_tarif,_frais ,_tva, _tcc, callback) {
分割相似的行:
saveContratEtudant: function (_nb_piece1,
_nb_piece2,
_shortadresse,
_govClt,
_villeClt,
_localiteClt,
_voieClt,
_cod_logem,
_adresse_logem,
_govLogem,
_gelgLogem, _dateDel,
_dateEffet,
_dateExp,
_nomAssure,
_prenomAssure ,
_piece2,
_numDocument,
_typeContrat,
_natureContrat,
_piece1,
_dateNais,
_email,
_phone,
_IdTrans,
_reference,
_numDocuemnt,
_codePostal,
_adresse,
_typedocu,
_sexeClt,
_tarif,
_frais,
_tva,
_tcc,
callback // <- HERE
) {
在调用它之前,应检查它是否已定义.或检查您的代码是否真的提供了该功能.
You should check if it's defined before calling it. Or check if your code provided really the function.
提示:函数中不应包含太多参数.
Pro tip : you should not have that much arguments in function.
所以您应该尝试这样:
.factory('Payement', function ($http, $ionicLoading) {
return {
saveContratEtudant: function (params, callback) {
$http({
method: 'POST',
url:SAVE_ETUDIANT,
timeout: 10000,
data: params,
}).then(function (response) {
callback(response);
// $ionicLoading.hide();
console.log("ajout ");
});
}
};
})
并这样称呼它:
Payement.saveContratEtudant($scope, function (data) {...})
这篇关于TypeError:回调不是函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!