Wednesday 10 May 2017

The request "DELETE" is not registered by the application

In my website, I have something like this :

<div class="mdl-cell--4-col mdl-grid">
            <label class="mdl-cell--6-col">Liste administrateurs</label>
              <select class="mdl-cell--6-col" ng-model="adminselected" ng-options="admin for admin in listAdmins">
              </select>
          </div>
          <div class="mdl-cell--2-col mdl-grid">
            <button class="mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect mdl-button--accent" style="float: right" layout-align="end center" ng-click="deleteAdmin()">Supprimer</button>
          </div>

The listAdmins, is managed, in the controller, by this way :

-An initialization with an authentification :

  forecastValue.authentification()
    .then(function(report) {
        $scope.currentName = report[0].informationUser.id_name;
          forecastValue.getAdmins($scope.currentName)
            .then(function(reports) {
                $scope.listAdmins = reports[0].listAdmins;
                console.log(reports[0].listAdmins);
                }).catch(function(err) {
                  $scope.listAdmins= [];
                  console.error('Unable to fetch forecast report: ' + err);
                  });

        }).catch(function(err) {
          $scope.currentName= '';
          console.error('Unable to fetch forecast report: ' + err);
          });

-The function, which delete the admin, it is after transmitted in the factory part in a post request.

  $scope.deleteAdmin = function() {


      forecastValue.deleteAdmin($scope.adminselected)
       .then(function(report){
          console.log("Changes saved");
          $scope.adminmessage = "L'utilisateur "+ $scope.adminselected+" n'est plus administrateur";
        }).catch(function(err){
         console.error("Changes not saved");
        });

         forecastValue.getAdmins($scope.currentName)
            .then(function(reports) {
                $scope.listAdmins = reports[0].listAdmins;
                }).catch(function(err) {
                  $scope.listAdmins= [];
                  console.error('Unable to fetch forecast report: ' + err);
        });

};

And the MySQL request, executed in the node.js code is the next one :

function deleteAdmin(res, queryParams)
{

  connection.query("DELETE FROM safeplusdb.admin WHERE name=\""+(decodeURIComponent(queryParams.admindeleted))+"\";");


  res.send({
    state: "OK"
  });
}

So, the result is the following :

-I check in the database, with the software Workbench, the data is deleted.

-In the website, nothing is registered, the data is still here, even if I do F5 or CTRL+F5. The only way to have the changes taken is to stop the application and restart it with command "node server.js".

When I have used update SQL methods, I had no problems like this.

How to explain it ?



via Simon Girard

No comments:

Post a Comment