jquery - Remove an item from the server with JSON -
this question has answer here:
- adding/removing items json data jquery 6 answers
i appreciate here. json knowledge limited, , can't solve it.
i need delete item shopping cart quick view create via json. front end seems work, doesn't because doesn't remove item json object.
the json object looks like.
[ { "id": 216687, "productid": 9604505, "catalogid": 306758, "name": "xxxxxxxxx1", "description": "", "quantity": 1, "totalprice": "38,00", "smallimage": "/images/products/large/xxxxx.jpg", }, { "id": 216687, "productid": 9604503, "catalogid": 306756, "name": "xxxxxxxxx1", "description": "", "quantity": 1, "totalprice": "38,00", "smallimage": "/images/products/large/xxxxx.jpg", } ]
jquery function:
//deleting items $(document).on('click', '.shopping-cart .delete i', function(){ var $target = $(this).parent().parent(); var $positions = $('.shopping-cart .item'); $target.hide(300, function(){ $.when($target.remove()).then( function(){ if($positions.length === 1) { $('.shopping-cart .items-list').remove(); $('.shopping-cart .title').text('shopping cart empty!'); } }); }); });
i think not deleting item properly.
i don't see you're trying delete item array. jquery little rusty, see dom manipulation going on.
you have find item in list , remove it.
// code elsewhere var id = 216687; removeitem(id); // function remove item function removeitem(id) { for(var = 0; < data.length; i++) { // don't know criteria removal is, can match property if (data[i].id == id) { // removes element when match found based on criteria removal var smallerarray = data.splice(i, 1); } } }
Comments
Post a Comment