Hey
I have a table, where i can delete an item, when i refresh the page the item i deleted is gone. I want the item to disappear when i click the delete link (“Slet”). I think the problem is that i just call the showCart(); function when the item is deleted and the showCart(); function still holds the same data as when the page was loaded. So how to i make it update, without a refresh?
[code=html]<script type=”text/javascript”>
// Load cart
showCart();
// AJAX – remove an item from cart
function removeItemFromCart(id){
$.get(“sites/sell.php”, {remove: id}, function(xml) {
var output = “ew”+xml;
$(‘#formOutput’).append(output);
});
// Reset cart
showCart();
}
// AJAX – gets items for cart
function showCart(){
$.get(“sites/sell.php”, {data: $(this).html()}, function(xml) {
var output = “”;
$(xml).find(‘product’).each(function() {
var id = $(this).find(‘id’).text()
var name = $(this).find(‘name’).text()
var amount = $(this).find(‘amount’).text()
var price = $(this).find(‘price’).text()
var totalPrice = $(this).find(‘totalPrice’).text()
output += “<tr><td>”+name+”</td><td>”+amount+”</td><td>”+price+”</td><td>”+totalPrice+”</td><td><a href=”#” onclick=”removeItemFromCart(‘”+id+”‘)”>Slet</a></td></tr>”;
output += “<tr><td colspan=’5′ class=’shop_cart_table_break’><img src=’images/grafics/blank.gif’ alt=” /></td></tr>”;
});
$(‘#table2’).html(output);
});
}
$(document).ready(function(){
// Toggle cart table
$(“#tablebar”).click(function(e){
$(“#table”).toggle(“slow”);
});
// Do something with submit
$(“form”).submit(function() {
if ($(“input:first”).val()) {
$(“#formOutput”).html(“Validated…”).show();
return false;
}
$(“#formOutput”).text(“Not valid!”).show().fadeOut(1000);
return false;
});
});
</script>