0

I am trying to update a status on database using this function of services

obj.post = function(q, object) {  
return $http.post(serviceBase + q, object).then(function(results) {
            return results.data;
    });
}

My query is working fine and data is updated on database but, after getting success message, when I try to get this row again from database using the same service function, my result shows that the status has not been update.

2
  • This question is not very clear. What do you mean by 'when I try to get this row again from the database using the same service(s) function'? Note that $http.get() and $http.post() operate differently but you did not clarify that in your code. Also it is not clear what you what you want to archive when you return a success message and want to get the update model at the same time. The possibilities are many. please add more info to guide visitors. Thanks. Commented Jun 8, 2015 at 16:52
  • I solved my problem to add a random number at the end of url as a query string at the end of url Commented Jun 9, 2015 at 7:20

1 Answer 1

1

Do something like this, Use $q service in angular to return a promise which will eventually get resolved with results.data

obj.post = function(q, object) {  
    $http.post(serviceBase + q, object).then(function(results) {
        return $q.resolve(results.data);
    });
}

Earlier you were directly returning the data , which might not be available immediately. So you should return a promise instead

Or, you can just do this ,

obj.post = function(q, object) {  
    return $http.post(serviceBase + q, object)     
}

this will return a do post and return a promise.

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.