jQuery not supposedly display multiple table

jQuery not supposedly display multiple table

Hi i need help on displaying table using jquery.

  1. <?php
  2.     if( $_POST["switch_3"] || $_POST["vegetarian"] ){
  3.         $donateAmount = $_POST["switch_3"];
  4.         $vegetarian = $_POST["vegetarian"];
  5.         if($vegetarian == ""){
  6.             $vegetarian = 0;
  7.         }
  8.         else{
  9.             $vegetarian = 1;
  10.         }
  11.     }
  12. ?>
  13. <script type="text/javascript">
  14.     // Check security token
  15.     jtoken = jQuery("#jtoken").find("input").serialize();
  16.     var donationAmount = '<?php echo $donateAmount; ?>';
  17.     var vegetarian = '<?php echo $vegetarian; ?>';
  18.     var url = "";

  19.     if(vegetarian == 0){
  20.         url = "/index.php?option=com_echarity&format=raw&task=api.get_suggestions&price=";
  21.     }
  22.     else{
  23.         url = "/index.php?option=com_echarity&format=raw&task=api.get_suggestions&vegetarian=1&price=";
  24.     }

  25.     jQuery.ajax({
  26.         type: "GET",
  27.         timeout: 10000,
  28.         url: url + donationAmount + "&" + jtoken,
  29.         success: function(data){
  30.             // console.log(data);
  31.             var dataResult = JSON.parse(data);
  32.             jQuery.each(dataResult, function(key,value){
  33.                 console.log('*************************************************************************************');
  34.                 console.log(value);
  35.                 console.log('*************************************************************************************');
  36.                 var charityID = value.charity_id;

  37.                 // Get charity detail - name and article link
  38.                 var url = "/index.php?option=com_echarity&format=raw&task=api.get_charity&charity_id=" + charityID;
  39.                 
  40.                 jQuery.ajax({
  41.                     type: "GET",
  42.                     timeout: 10000,
  43.                     url : url + "&" + jtoken,
  44.                     success: function(data){
  45.                         console.log(data);
  46.                         var dataResult = JSON.parse(data);
  47.                         
  48.                         var content = '<table id="tableDonate" class="table table-hover">';
  49.                         var heading = '<tr>';
  50.                         var datas = "";
  51.                         heading += '<th>' + 'Charity' + '</th>' + '<th>' + 'Products' + '</th>' + '<th>' + 'Quantity' + '</th>' + '<th>' + 'Amount' + '</th>';
  52.                         heading += '</tr>';
  53.                         heading += '<tr>';
  54.                         jQuery.each(dataResult, function(key,value){
  55.                             charityName = value.charity_name;
  56.                             
  57.                             console.log('*************************************************************************************');
  58.                             console.log(charityName);
  59.                             console.log('*************************************************************************************');
  60.                             datas += '<td>' + charityName + '</td>';
  61.                             datas += '<td>' + '' + '</td>';
  62.                             datas += '<td>' + '' + '</td>';
  63.                             datas += '<td>' + '' + '</td>';
  64.                             datas += '</tr>';
  65.                         });
  66.                         datas += '</table>';
  67.                         content += content + heading + datas;
  68.                         jQuery('#contentNeed').append(content);
  69.                     }
  70.                     
  71.                 });
  72.             });
  73.         },
  74.         error: function (request, status, error) {
  75.             alert(request.responseText);
  76.         }
  77.     });
  78. </script>

  79.  <div id="contentNeed">

  80.         </div>
Why it display multiple table for multiple result? Did i do something wrong on the script? Can someone point me to the correct direction.