Ich habe einen Online-Shop mit einem Einkaufswagen. Der Warenkorb, ein <table>
, aktualisiert seinen Inhalt, nachdem er einen Artikel zum Warenkorb hinzugefügt hat.
Ich verwende die Methode AJAX von jQuery, die als Antwort vom aufgerufenen PHP -Skript HTML <td><tr>
empfängt. _. Die Firebug-Konsole zeigt die richtige Antwort des Aufrufs an.
Wie Sie in meinem Code sehen können, möchte ich der Tabelle HTML hinzufügen. Ich kann es nicht zum Laufen bringen ... Verstehe ich die Methode AJAX nicht? Ich möchte diese <td><tr>
zur Einkaufswagen-Tabelle hinzufügen.
$.ajax({
url: 'php/addToShoppingCart.php',
type: 'POST',
dataType: 'html',
data: content,
complete: function(data) {
$('#shop section table tbody').append(data);
},
});
habe es mit .done () versucht?
$.ajax({
url: 'php/addToShoppingCart.php',
type: 'POST',
dataType: 'html',
data: content,
}).done(function ( data ) {
$('#shop section table tbody').append(data);
});
Sie können den Erfolg auch nutzen
$.ajax({
url: 'php/addToShoppingCart.php',
type: 'POST',
dataType: 'html',
data: content,
success : function(data)
{$('#shop section table tbody').append(data);}
});
Die Syntax für complete
lautet
$.ajax({
url: 'php/addToShoppingCart.php',
type: 'POST',
dataType: 'html',
data: content,
}).complete(function (data) {
$('#shop section table tbody').append(data);
});
Gut in Ihrem Einkaufswagen erstellen Sie eine Tabelle und eine tr, damit Sie Titel oben anzeigen können
<table cellpadding="5" cellpadding="2" border="0" id="cartprod">
<tr>
<td width="60%"><b>Product Name</b></td>
<td width="20%"><b>Quantity</b></td>
<td width="20"><b>Price</b></td>
</tr>
</table>
Dann können Sie Ihren Inhalt so anhängen
function AddToCart(pid)
{
$.post('php/addToShoppingCart.php',{pid:pid},function(data){
$('#cartprod tr:first').after(data);
},'html')
}