数据表和行详细信息

时间:2018-05-01 15:54:26

标签: javascript php jquery json datatable

PHP代码返回我的表但调试JavaScript代码我看到它没有执行function(data)所以只留下“添加”类。我的代码出了什么问题?我该如何解决?

function format(d) {
  var div = $('<div/>').addClass('loading').text('Loading...');

  var product_id = d['DT_RowId']; //This is the ItemId
  var btn_action = 'item_detail';

  $.ajax({
    url: 'item_action.php', //Calling the function
    type: "POST",
    data: {
      product_id: product_id,
      btn_action: btn_action //Set item_id and variable
    },
    dataType: 'json',
    success: function(data) { //If data is success it will write the html
      div.html(data.html).removeClass('loading');
    },
    error: function() {
      $('#item_data').html('Bummer: there was an error!');
    }
  });

  return div;
}
$data = array();
$data[] = '<table class="table table-bordered table-striped dataTable no-footer" cellpadding="5" cellspacing="0" border="0" style="padding-left: 50px">';               

foreach($result as $row) <!--Fill the table cells-->
{   
  $sub_array = array(); <!--Set the array to fill with datafields-->
  $sub_array[] = '<tr>';
  $sub_array[] = '<td>Price Code</td>';
  $sub_array[] = '<td>'.$row["pricecode_code"].'</td>';
  $sub_array[] = '</tr>';
  $data[] = $sub_array;
}   

$data[] = '</table>';   <!--Closing table-->
echo json_encode($data); <!--Return the table formatted-->

0 个答案:

没有答案
相关问题