Tomkay Tomkay - 3 months ago 25
HTML Question

How to output the response HTML data by a jQuery AJAX request?

I have an online shop with a shopping cart. The cart, which is a

<table>
, refreshes its content after adding an article to the cart.


I use jQuery's AJAX method which receives HTML
<td><tr>
as a response from the called PHP script.
Firebug's console shows the correct response from the call.


As you can see in my code, I want to add HTML to the table. I can't get it to work.
Do I not understand the AJAX method? I want to add these
<td><tr>
to the shopping cart table.

JavaScript (Using jQuery 1.9.1)



$.ajax({
url: 'php/addToShoppingCart.php',
type: 'POST',
dataType: 'html',
data: content,

complete: function(data) {
$('#shop section table tbody').append(data);
},
});





Firebug console



enter image description here

Answer

have tried it using .done()?

$.ajax({
  url: 'php/addToShoppingCart.php',
  type: 'POST',
  dataType: 'html',
  data: content,
}).done(function ( data ) {
  $('#shop section table tbody').append(data);
});
Comments