我正在使用CodeIgniter rest应用程序和ribs.js开发一个应用程序。
我正在尝试从数据库中删除一条记录。骨干模型返回成功回调,数据库数据未删除。
$("#deleteItem").click(function (event) {
event.preventDefault();
console.log("toing" + deleteItemID);
var deleteUserModel = Backbone.Model.extend({
urlRoot: "http://localhost/WishListApplication/index.php/listItem/removeItem",
defaults: {
userId: '',
itemURL: ''
}
});
var removeItem = new deleteUserModel({userId: <?php echo $this->session->userdata('userId'); ?>,
itemURL: deleteItemID});
removeItem.destroy(
{
success: function (model, response, options) {
console.log(response);
$('#delete-item').modal('hide');
console.log("The model has deleted the server");
},
error: function (model, xhr, options) {
console.log("Something went wrong while deleting the model");
}
});
});
这是我的控制器类
public function removeItem_delete() {
$userId = $this->delete('userId');
$itemURL = $this->delete('itemURL');
$deletedItem = $this->itemModel->deleteItem($userId, $itemURL);
//checks whether item has successfully deleted from the database
if ($deletedItem !== false) {
//display sucess message
$data['messages'] = 'Item has been deleted successfully';
$data['success'] = true;
} else {
$data['messages'] = 'Something went wrong - Please try to delete Item again';
$data['success'] = false;
}
echo json_encode($data);
}
我是骨干新手。请有人帮我解决这个问题。
预先感谢