0

Currently I have 2 functions which call some of my API endpoints. They're setup to take a request followed by a success & failure callback functions. I'm trying to call my DeleteTask function from the success callback of my DeleteTaskUser function. However the DeleteTaskUser function is never firing.

I am pretty new to javascript, trying to build this application as a way to learn it so I could be misunderstanding how to use callbacks in javascript.

Any ideas?

The 2 functions:

    this.DeleteTaskUser = function(request, success, failure){
        AuthService.resHttp({
                method: 'DELETE',
                resource: 'DeleteAssignments',
                params : request
        }).then(
                function(res) {
                        success(res)
                },
                function(res) {
                        failure(res)
                }
        );
    }

                this.DeleteTask = function(request, success, failure){
                    AuthService.resHttp({
                            method: 'DELETE',
                            resource: 'Task',
                            data : request
                    }).then(
                            function(res) {
                                    success(res)
                            },
                            function(res) {
                                    failure(res)
                            }
                    );
                }

I am trying to call the functions as follows:

 for(i = 0; i < $scope.tasksList.length; i++){

 TaskApi.DeleteTaskUser(
     {
         id: $scope.tasksList[i].id,
     },
        //handle success
        function(res){
            //This function is never firing, despite the above function succeeding. 
            console.log("After Task User Deletion");
            TaskApi.DeleteTask(
                     {
                         id: $scope.tasksList[i].id,
                     },
                     function(res){},
                     function(res){}
                 )
        },
        //handle failure
            function(res){
                console.log(res);

        }
)

}
jackfrost5234
  • 229
  • 5
  • 12
  • what does success(res) function do? Does it return anything? – Jayakrishnan Jun 11 '17 at 05:22
  • I'm not sure what you mean. I think success(res) should just call whatever function you pass as an argument as success and then execute that function on success. I.e. if DeleteTaskUser succeeds, the DeleteTask function should be fired because it was passed in as the success callback function. – jackfrost5234 Jun 11 '17 at 05:30
  • OK I got it now, just put debugger before **success(res)** in **DeleteTaskUser** function to check whether the success callback is being hit or not – Jayakrishnan Jun 11 '17 at 05:33
  • I already know its not being hit because the console.log() is never being printed. That being said, do you have a link to how to use the debugger? – jackfrost5234 Jun 11 '17 at 05:36
  • You have to simply write **debugger;** before **success(res)** in **DeleteTaskUser** function.Check out https://www.w3schools.com/jsref/jsref_debugger.asp – Jayakrishnan Jun 11 '17 at 05:39
  • or you con simply insert console.log in the success function in DeleteTaskUser to see if the success ever get called. – digitake Jun 11 '17 at 06:03
  • Try to add a .catch() after then(). Maybe your promise fails? – sadpanda Jun 11 '17 at 06:13

0 Answers0