php


jQuery, items not being deleted form cart correctly


I'm quite new to jQuery. I am building a shopping cart and trying to delete products from a cart. If I have one item in the basket and then remove it, it will disappear, but if I add another item to the cart, the item I deleted will reappear. If I have a card with more than one object, when I attempt to delete it, it will only change the total.
$('.addToCart').click(function(){
var id = this.id;
var price = parseFloat($('#priceAdd-'+id).val()).toFixed(2);;
var name = $('#name-'+id).val();
var total =(parseFloat($('#total').text())+parseFloat(price)).toFixed(2);
cartSize++;
$('#product-'+id).fadeOut('fast');
$('#added-'+id).delay(500).fadeIn('fast');
$.ajax({
type: "POST",
url: 'resources/addToCart.php',
data: { itemId: id , name: name, price: price},
cache: false,
success: function(html){
$("ol").append(html).slideDown("slow");
$('#noItems').fadeOut('fast');
$('#total').html(total);
$('#mainCart').fadeIn('fast');
}
});
});
$('ol').on("click",'.del',function(e){
var id= e.target.id;
var productId = $('#productId-'+id).text();
var productPrice = $('#price-'+id).text();
var total = $('#total').text();
var newPrice = (parseFloat(total) - parseFloat(productPrice)).toFixed(2);
var dataString = 'id='+ id;
cartSize--;
alert(id);
$('#total').html(newPrice);
$("#cart-"+id).remove();
$.ajax({
type: "POST",
url: "resources/del.php",
data: { id: id },
cache: false,
success: function(html){
$('#added-'+productId).fadeOut('Fast');
$('#product-'+productId).delay(600).fadeIn('Fast');
if(cartSize == 0){
$('#noItems').fadeIn('Fast');
$('#mainCart').fadeOut('Fast');
}
}
});
return false;
});
Any input would be appreciated
Thank you
edit: is there anyone else who can help me?
I think when you are calling to "resources/del.php", this is not deleting the item in Server (only visually) and then when you add another with "resources/addToCart.php", this is returning ALL the items (even the one you think you remove)

Related Links

PHP outputs a strange french character | é = string(3)
How do I access third table via Many-to-Many Relation in Laravel?
Return data to controller after model function
How to get all products from category with any price in OpenCart?
Dropdown menu from mysql database
PHP for / while loop - Calculate dates based on starting date and interval
Update another column during a update query based on its new value
javascript multidimensional array out of mysql table - dont know whats that kind of Object Object
how to check a parameter is null or empty in mysql?
Opencart how unserialize(): Error is generated while saving data to database
External captive portal fortigate
wordpress theme twentysixteen page content not Display
How to validate name="novs[78][] using jquery validation?
PHP does a subsequently required file have access to previous requirements?
Get authentication work with SOAP and PHP
only the first two values is considering from the date while fetching the result

Categories

HOME
php
svn
lambda
clearcase
exchange-server
windows-10
operating-system
kivy
ews
plpgsql
semantic-web
cryptography
openflow
turbojpeg
sentry
anchor
solution
lapack
pm2
sonicwall
twisted
pinterest
gravity
android-custom-view
jest
gollum-wiki
connection-refused
pdf.js
fusetools
android-cardview
copy-protection
phpstorm-2016.1
fotorama
django-crispy-forms
mv
iscroll
jacoco-maven-plugin
icepdf
docker-ucp
flume-twitter
hibernate-ogm
comm
node-apn
sigsegv
nivo-slider
ptvs
glimpse
swiperefreshlayout
business-rules
portal
ipywidgets
metabase
bigdecimal
xmlbeans
fuzzer
dmarc
pyaudio
mathml
processor
phpquery
fanotify
nastran
ambiguity
uitest
angular-amd
relational-model
scala-macros
html-escape-characters
findersync
xhprof
xcode6.3.1
siena
incognito-mode
iosched
principalcontext
xsd2code
mute
mp4parser
sunstudio
dynamic-rdlc-generation
ofstream
gprof
wndproc
gamesalad
gwt-celltable
zend-server-ce
servercontrol
haiku
filelock
mongrel2
multiple-users
aggregator
iphone-sdk-4.3
firephp
fuzzy-comparison
chronic
downloadfile

Resources

Encrypt Message