看板 Ajax 關於我們 聯絡資訊
不好意思第一次發文,所以再重新發一次! 我想問的問題是,我想刪掉列表出來的項目, 畫面可以刪除,但是後端接收不到。 HTML部分: <body> <div ng-controller="firstCtrl"> 書名:<input type="text" ng-model="name" placeholder="輸入書名"> 作者:<input type="text" ng-model="author" placeholder="輸入作者"> <button type="button" ng-click="add()">新增</button> <button type="button" ng-click="showList()">列出</button> <table class="table table-striped" > <tr colspan="5"> <td></td> <td>ID</td> <td>書名</td> <td>作者</td> <td></td> </tr> <tr ng-repeat="data in list"> <td><a href="" ng-click="remove($index)">X</a></td> <td>{{data.id}}</td> <td><span ng-hide="isShow"></span> <span> <input ng-show="isShow" type="text" ng-model="nameEdit" > </span> </td> <td>{{data.author}}</td> <td> <button type="button" ng-click="editShow(data)"> <span ng-hide="isShow">修改</span> <span ng-show="isShow">確認</span> </button> <button type="button">取消</button> </td> </tr> </table> <button ng-hide="clear" type="button" ng-click="rset()">全部清除</button> </div> JS部分: $scope.list = [] $scope.clear = true; $scope.showList = function() { $http({ url: 'http://localhost:2000/book', method: 'GET', }).then(function(success_response) { console.log(success_response); $scope.list = success_response.data; }, function(err_response) { console.log(err_response); }) if ($scope.clear = true) { $scope.clear = false; } } //刪除 $scope.remove = function(idx) { $scope.list.splice(idx, 1) var id = $scope.list.id; $http.delete('http://localhost:2000/book/', { id: id }).then(function(res) { $scope.showList(res); console.log(idx); }) } -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 36.226.218.32 ※ 文章網址: https://www.ptt.cc/bbs/Ajax/M.1464460451.A.9FF.html
No: var id = $scope.list.id; 看起來怪怪的 05/29 02:40
No: 是想寫 var id = $scope.list.splice(idx, 1)[0].id; 嗎? 05/29 02:42
aaa7513231: log(id)看你有沒有正確傳給後端,然後測 05/29 09:30
aaa7513231: 試資料給後端看能不能刪除,就知道是前端 05/29 09:30
aaa7513231: 試資料給後端看能不能刪除,就知道是前端 05/29 09:30
aaa7513231: 有問題題還是後端有問題 05/29 09:30
hope0330: console 出來是正確的選到要刪除的ID,但是變成畫面 05/29 15:49
hope0330: 畫面不會改變刪掉的還是在上面但沒有錯誤 05/29 15:50
ccvs: 你文章裡面說畫面可以正常刪除 可是推文又說是畫面無法刪除 05/30 01:25
ccvs: 都幾? 05/30 01:25
conanist: 你先把後端MARK,然後你畫面上可以正常刪除資料嗎? 06/07 17:54
conanist: 然後$http.delete 這行真的有去刪後端的資料嗎 06/07 17:56
conanist: 試完在回來PO一下結果 06/07 17:57