jeudi 3 novembre 2016

Checkbox changes state when async call is made to the server

I use VS2015 and angular.

I have a checkbox and a drop down list on a form. Code:

    <input id="chkStatus" type="checkbox" ng-model="UserStatus" 
                         ng-true-value="'1'" ng-false-value="'2'" ng-change="ChangeLabelText();" />

  <select id="ddWayBill" class="form-control txtTextBox" data-editable="1" ng-model="WayPayment">
              <option value="1">Prvi status</option>
              <option value="2">Drugi status</option>
              <option value="2">Drugi status</option>
              <option value="2">Drugi status</option>
              <option value="2">Drugi status</option>
              <option value="2">Drugi status</option>
            </select>

I use this code (angular) to make POST to the server:

 $http({
      method: "POST",
      url: $scope.UrlGetUsers,
      data: JSON.stringify(model)
    }).then(function success(response) {
      if (response.data === "-1") {
        alert("Updating was not successful!");
      }
    }, function failure() {
      alert("Error while updating!");
    })

My problem is that when I make this call to the server, checkbox gets unchecked and select list also loses chosen element. Basically check box and select are behaving just like I would press F5 and refresh the page. Why is that? Call is made asynchronously.




Aucun commentaire:

Enregistrer un commentaire