How to wait until an http request is finished before moving on?

Graeham Broda

I am currently accessing a database through http requests, however in the function below, i am having issues as the request is completed after the data is needed.

$scope.submitUserName = function() {
    console.log("button got clicked")
    $http({
        method: 'GET',
        url: '/data/Graeham'
    }).then(function successCallback(response) {
        $scope.dataStuff = response;
        console.log($scope.dataStuff);
    }, function errorCallback(response) {
        // called asynchronously if an error occurs
        // or server returns response with an error status.
    });
    console.log($scope.formData.userName);
    console.log($scope.dataStuff);

    for (var i = $scope.dataStuff.data.length - 1; i >= 0; i--) {
        if ( $scope.formData.userName == $scope.dataStuff.data[i].ASSIGNED_TO && $scope.dataStuff.data[i].PRIMARY_UCID == "Y" ) {

            console.log($scope.dataStuff.data[i]);
            console.log($scope.dataStuff.data[i].UCID)

            $scope.assignedData.push($scope.dataStuff.data[i]);
            $scope.assignedUCID.push($scope.dataStuff.data[i].SUSPECT_UCID);

        }

    }
    console.log($scope.assignedData)
};

i cannot figure out what statement i need to ad to the http get to make it complete before moving onto the for loop.

Linus Borg

the for loop has to be in the successCallback ( or in a function called from there).

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

How to wait until all async calls are finished

From Dev

Wait until function is finished

From Dev

How to make python wait until the previous task is finished?

From Dev

In NodeJs how can I wait until my http get is finished?

From Dev

How to wait until all tasks are finished before running code

From Dev

Wait until all iOS blocks are executed before moving on

From Dev

how to wait until a web request with HttpWebRequest is finished?

From Dev

How to wait until some jQuery methods are finished?

From Dev

wait until completion block not finished in AFJSONRPCClient request

From Dev

How to wait until an animation is finished in Swift?

From Dev

How to wait until my batch file is finished

From Dev

How to wait until networking by Alamofire has finished?

From Dev

How to wait until all tasks finished without blocking UI thread?

From Dev

Selenium wait.until to check ajax request finished is throw error

From Dev

How do I make an Excel RefreshAll wait to close until finished?

From Dev

How to make Gulp wait until dest file is finished?

From Dev

How can I wait until Asynchronous callbacks are finished before using the data retrieved?

From Dev

How to wait until all NSOperations is finished?

From Dev

How to wait until find method has finished before doing further processing in Ember Model

From Dev

How to make python wait until the previous task is finished?

From Dev

Wait until all iOS blocks are executed before moving on

From Dev

How can I wait until NSXMLParserDelegate methods finished?

From Dev

wait until completion block not finished in AFJSONRPCClient request

From Dev

How to make JS wait until protocol execution finished

From Dev

guzzle concurrent request, wait for finished batch before sending next

From Dev

How to get jQuery to wait until an animation is finished?

From Dev

How to make a python Script wait until download has finished

From Dev

Android - How to wait until a SnapshotListener has finished?

From Dev

How to wait until canvas has finished re-rendering?

Related Related

  1. 1

    How to wait until all async calls are finished

  2. 2

    Wait until function is finished

  3. 3

    How to make python wait until the previous task is finished?

  4. 4

    In NodeJs how can I wait until my http get is finished?

  5. 5

    How to wait until all tasks are finished before running code

  6. 6

    Wait until all iOS blocks are executed before moving on

  7. 7

    how to wait until a web request with HttpWebRequest is finished?

  8. 8

    How to wait until some jQuery methods are finished?

  9. 9

    wait until completion block not finished in AFJSONRPCClient request

  10. 10

    How to wait until an animation is finished in Swift?

  11. 11

    How to wait until my batch file is finished

  12. 12

    How to wait until networking by Alamofire has finished?

  13. 13

    How to wait until all tasks finished without blocking UI thread?

  14. 14

    Selenium wait.until to check ajax request finished is throw error

  15. 15

    How do I make an Excel RefreshAll wait to close until finished?

  16. 16

    How to make Gulp wait until dest file is finished?

  17. 17

    How can I wait until Asynchronous callbacks are finished before using the data retrieved?

  18. 18

    How to wait until all NSOperations is finished?

  19. 19

    How to wait until find method has finished before doing further processing in Ember Model

  20. 20

    How to make python wait until the previous task is finished?

  21. 21

    Wait until all iOS blocks are executed before moving on

  22. 22

    How can I wait until NSXMLParserDelegate methods finished?

  23. 23

    wait until completion block not finished in AFJSONRPCClient request

  24. 24

    How to make JS wait until protocol execution finished

  25. 25

    guzzle concurrent request, wait for finished batch before sending next

  26. 26

    How to get jQuery to wait until an animation is finished?

  27. 27

    How to make a python Script wait until download has finished

  28. 28

    Android - How to wait until a SnapshotListener has finished?

  29. 29

    How to wait until canvas has finished re-rendering?

HotTag

Archive