jQuery not supposedly display multiple table
Hi i need help on displaying table using jquery.
- <?php
- if( $_POST["switch_3"] || $_POST["vegetarian"] ){
- $donateAmount = $_POST["switch_3"];
- $vegetarian = $_POST["vegetarian"];
- if($vegetarian == ""){
- $vegetarian = 0;
- }
- else{
- $vegetarian = 1;
- }
- }
- ?>
- <script type="text/javascript">
- // Check security token
- jtoken = jQuery("#jtoken").find("input").serialize();
- var donationAmount = '<?php echo $donateAmount; ?>';
- var vegetarian = '<?php echo $vegetarian; ?>';
- var url = "";
- if(vegetarian == 0){
- url = "/index.php?option=com_echarity&format=raw&task=api.get_suggestions&price=";
- }
- else{
- url = "/index.php?option=com_echarity&format=raw&task=api.get_suggestions&vegetarian=1&price=";
- }
- jQuery.ajax({
- type: "GET",
- timeout: 10000,
- url: url + donationAmount + "&" + jtoken,
- success: function(data){
- // console.log(data);
- var dataResult = JSON.parse(data);
- jQuery.each(dataResult, function(key,value){
- console.log('*************************************************************************************');
- console.log(value);
- console.log('*************************************************************************************');
- var charityID = value.charity_id;
- // Get charity detail - name and article link
- var url = "/index.php?option=com_echarity&format=raw&task=api.get_charity&charity_id=" + charityID;
-
- jQuery.ajax({
- type: "GET",
- timeout: 10000,
- url : url + "&" + jtoken,
- success: function(data){
- console.log(data);
- var dataResult = JSON.parse(data);
-
- var content = '<table id="tableDonate" class="table table-hover">';
- var heading = '<tr>';
- var datas = "";
- heading += '<th>' + 'Charity' + '</th>' + '<th>' + 'Products' + '</th>' + '<th>' + 'Quantity' + '</th>' + '<th>' + 'Amount' + '</th>';
- heading += '</tr>';
- heading += '<tr>';
- jQuery.each(dataResult, function(key,value){
- charityName = value.charity_name;
-
- console.log('*************************************************************************************');
- console.log(charityName);
- console.log('*************************************************************************************');
- datas += '<td>' + charityName + '</td>';
- datas += '<td>' + '' + '</td>';
- datas += '<td>' + '' + '</td>';
- datas += '<td>' + '' + '</td>';
- datas += '</tr>';
- });
- datas += '</table>';
- content += content + heading + datas;
- jQuery('#contentNeed').append(content);
- }
-
- });
- });
- },
- error: function (request, status, error) {
- alert(request.responseText);
- }
- });
- </script>
- <div id="contentNeed">
- </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.