M
M
moveOn2018-05-22 17:54:06
JavaScript
moveOn, 2018-05-22 17:54:06

How to force the frontend to fetch data after completing a query to the database on the server?

There is a code like this in angularjs

CPElement.update({id: $scope.elements[elemId].id}, $scope.elements[elemId]).then($scope.calculate());

CPElement is a resource. The data is sent to the server. They are stored on the server. After receiving a response from the server, .then() starts a recalculation request on the server.
The problem is that the recalculation response comes before the actual data in the update request is applied to the database.
I need to send data and receive the result of calculations taking into account them. And now it either succeeds or fails.
Server part on yii2. Controllers are different for saving and for computing.
Tell me where to dig.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
moveOn, 2018-05-23
@moveOn

As a result, y passed the update function parameter to calback and it worked.

CPElement.update({id: id}, data,function(){

                    $scope.calculate()
                })

M
Maxim Timofeev, 2018-05-22
@webinar

1. yii has nothing to do with it
2. Do you understand that then and when are fundamentally different words?
https://docs.angularjs.org/api/ng/service/$q#when

V
Vitaly, 2018-05-22
@rim89

The problem is that the recalculation response comes before the actual data in the update request is applied to the database.

wait until the UPDATE is completed and therefore already send ... mb via @amount or SELECT new data at the query level to SQL, if SQL is used

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question