John Davidson

javascript - Show in a div the content of a table that comes in an array after being called from with ajax


From a template I am calling a method in php through ajax and this returns an array that has keys with numerical values and html code; The numeric values are shown to me correctly but the key that has a value with html code shows it to me as empty.

My array

$content_taxes= '<tr>
<td>VAT SuperReducted </td>
<td class="text-right">4.00</td>
<td class="text-right">140</td>
<td class="text-right">5.6</td>
<td>VAT Reducted</td>
<td class="text-right">10.00</td>
<td class="text-right">0</td>
<td class="text-right">0</td>
<td>VAT General </td>
<td class="text-right">21.00</td>
<td class="text-right">1360</td>
<td class="text-right">285.6</td>

$content_taxes = [ 'status' => true,
'content_taxes'=> $content_taxes,
'sub_total_invoice' =>($total_invoice - $sub_total_taxes),
'sub_total_taxes' => $sub_total_taxes,
'total_invoice' => $total_invoice,

return json_encode($content_taxes);

Now in the template after I have called it I get

method : "POST",
url: "/invoices/calculate_totals",
data: {
"_token" : '{{ csrf_token() }}',
"parameters" : data_inputs,

dataType: "json",
success: function(data) {

if(data.status) {

$("#total_taxes").html(data.content_taxes); //SHOWS it EMPTY

$(".sub-total").html(data.sub_total_invoice); // it shows it correctly
$("#sub_total").val(data.sub_total_invoice); // it shows it correctly

$(".total-taxes").html(data.sub_total_taxes); // it shows it correctly
$("#total_taxes").val(data.sub_total_taxes); // it shows it correctly

$(".total-invoice").html(data.total_invoice); // it shows it correctly
$("#total_invoice").val(data.total_invoice); // it shows it correctly

In the sample console:


Table column content

<table class="table">
<th>Tax description</th>
<th class="text-right">Value%</th>
<th class="text-right">Total</th>
<th class="text-right">VAT</th>
<tbody id="total_taxes">

**************** You have to show me here. *****************


What am I doing wrong!!!

Thanks for all greetings.

I expected to show the key that has the value with html code in a div but it prints empty.

My Answer:
0 => '5%',
1 => '10%',
2 => '15%'

Rate this post

3 of 5 based on 9608 votes


© 2024 - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us