0

I am getting question list from server with get request. Some of questions are unread and their attribute is

"okundu":"0";

I want to change it to

"okundu":"1";

In my code below I get questions from service and try to put request in loop. But it doesn't work due to async problem. I am new in angular.js .How can I solve this problem ?

$http.get('http://example/sorus?userId='+sessionStorage.refUser).success(function(response){         
        sorus=response;
        
        for(var i=0;i<sorus.length;i++){
            
            if(sorus[i].okundu=="0"){
                console.log(sorus[i]._id)
                $http.put('http://example/sorus/'+sorus[i]._id,{"okundu":"1"}).success(function(response){console.log(response)}).error(function(err){console.log("ERR : " + err)})
            }
            
        }
        
    })

in put request it always goes to error function and err returns null.If I write console.log above of put request I see that result is

59817b57a720c13e31d3def4

59817b46a720c13e31d3def3

ERR : null

ERR : null

There is async problem here. It never enters success of put request. It goes to error of put request.

2
  • Response result please Commented Aug 4, 2017 at 7:14
  • What is the issue here? Please explain. Your code should work fine Commented Aug 4, 2017 at 7:15

1 Answer 1

0

You can take the result from your post success method in a variable ($scope.itemList for example). Out of the success method of your post, you can post these variables using $resource method.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.