简体   繁体   中英

depends on one ajax call response call another ajax call in angularjs

first I called userSignupSubmit function.Inside this method call another method mobilenocheckingmethod , depends on this ajax call response to call another ajax call but second call it will not work.

    var crm = angular.module('crm');
    crm.controller("userCheckingController", function($scope,service, $http) {


    var key="";

    $scope.mobilenoCheckingSubmit = function() {


        var dataObject="serialNo="+$scope.mobileno;

        alert(dataObject);
        $http({
             method:'POST',
             url:'registerDevice',
             data:dataObject,
             headers:{'Content-Type':'application/x-www-form-urlencoded'}
             }).
            success(function(data, status, headers, config) {

                var code=data.code;

                if(code!=200)
                {
                    alert("mobileno200"+data.message);
                    key=data.clientKey;

                    this.userSignup();
                }
                else
                {
                    alert("mobileno201"+data.message);
                    alert("mobileno201"+data.clientKey);
                    key=data.clientKey;
                  this.userSignup();

                }   



            }).
        error(function(data, status, headers, config) {

            $scope.user_error_status="Inside Error Occur";
            return;

            }).

        //this.userSignup();
    }

   $scope.userSignupSubmit = function() {



        this.mobilenoCheckingSubmit();

    }
   $scope.userSignup=function(){


        var dataObject="email="+$scope.signupEmail+"&key="+key;

        alert(dataObject);
        $http({
             method:'POST',
             url:'signUp',
             data:dataObject,
             headers:{'Content-Type':'application/x-www-form-urlencoded'}
             }).
            success(function(data, status, headers, config) {

                var code=data.code;

                if(code === 201)
                {
                    alert(data.message);

                }
                if(code === 200)
                {
                    alert(data.message);

                }
                if(code === 409)
                {


                    service.Key(data.Key);
                    $scope.manual_dashboard = true;
                    $scope.userChecking = true;

                }   



            }).
       error(function(data, status, headers, config) {

        $scope.signup_error_status="Inside Error Occur";

            });

       }
    });

You code should use $scope.userSignup(); instead of this.userSignup(); which will call your scope method on success of ajax call.

Code

success(function(data, status, headers, config) {
    var code = data.code;

    if (code != 200) {
        alert("mobileno200" + data.message);
        key = data.clientKey;

        $scope.userSignup(); //<-- change here
    } else {
        alert("mobileno201" + data.message);
        alert("mobileno201" + data.clientKey);
        key = data.clientKey;
        $scope.userSignup(); //<-- change here

    }
})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM