简体   繁体   中英

Angular JS $http does not respond updated data from database

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.

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.

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