Javascript Ajax/jquery函数未从返回的JSON/PHP表格单元格值接收id

Javascript Ajax/jquery函数未从返回的JSON/PHP表格单元格值接收id,javascript,php,jquery,ajax,json,Javascript,Php,Jquery,Ajax,Json,我已经从一个JSON数组创建了一个表(用于datatables),并在数组中嵌入了一个链接,该链接具有一个ID(mysql表中的主键),该ID应该触发一个动态模式,以获取额外的信息。JSON中嵌入的特定行如下所示: "provider_name":"COTTAGE GROVE COMMUNITY HOSPITAL<\/a>" 在PHP中: $results['provider_name'] = "<a id='".$results['id']."' data-toggle='

我已经从一个JSON数组创建了一个表(用于datatables),并在数组中嵌入了一个链接,该链接具有一个ID(mysql表中的主键),该ID应该触发一个动态模式,以获取额外的信息。JSON中嵌入的特定行如下所示:

"provider_name":"COTTAGE GROVE COMMUNITY HOSPITAL<\/a>"
在PHP中:

$results['provider_name'] = "<a id='".$results['id']."' data-toggle='modal' href='#provmodal' class='push'>".$results['provider_name']."</a>";
当我单击模式触发器时,
console.log()
没有返回任何内容,因此我知道它没有从
id
属性接收它

我是否正确地将链接嵌入json

我有点困惑,因为我实际上让这个脚本在另一个页面上工作,唯一的区别是它不是一个外部ajax json源代码。我将在页面上生成json数组,并将其回显到datatables“aaData”的javascript变量中,然后以这种方式填充该表。不过我更喜欢从外部请求json,这就是我遇到这个问题的原因

:编辑:

这里是modalquery_providerlist.php,按要求-->


你能展示你的PHP代码吗?只是一个旁注,我试着用echo代替print\r,但没有什么不同为什么要这么多print\r?尝试将所有内容收集到一个变量中,然后在末尾用exit回显该变量。例如echo$html;退出@AnandGhaywankar这是旧代码,我会继续修改它,但它不能解决我的问题,模态仍然是空的
$(function(){
    $('.push').on('click', function(){
      var ele_id = $(this).attr('id');
      console.log(ele_id);
       $.ajax({
          type : 'post',
           url : 'modalquery_providerlist.php', // in here you should put your query 
          data :  'post_id='+ ele_id, // here you pass your id via ajax .
                     // in php you should use $_POST['post_id'] to get this value 
       success : function(r)
           {
              // now you can show output in your modal 
        $("#provmodal .modal-body").html(r).promise().done(function(){
        $("#provmodal").modal('show');  
                     });
           }
         });
    });
 });
<?php
include_once("functions.php");
require_once("link_provlist_2013.php");
$id = $_POST['post_id'];

$modalquery = $link->prepare("SELECT * FROM prov_stats WHERE id = :id");
$modalquery->bindParam(':id', $id, PDO::PARAM_INT);
$modalquery->execute();
$modalresults = $modalquery->fetch(PDO::FETCH_ASSOC));

//calc fields
$adc = ($modalresults['pat_days']/365);
$alos = ($modalresults['pat_days']/$modalresults['disc']);
if($modalresults['total_charity_uncomp_cost'] != 0){
$charity_disp = "\$".number_format($modalresults['total_charity_uncomp_cost']);
} else {
    $charity_disp = "<b style='color:red'>Not Reported</b>";
}
$all_other = 100 - ((($modalresults['medicare']/$modalresults['disc']) * 100) + (($modalresults['medicaid']/$modalresults['disc']) * 100));

//printing onto the modal
print_r("<img width='225' height='100' class='pull-right' src='/photoshop/hds/logo_mini_fade.png' />");
print_r("<h4>Name: ".$modalresults['provider_name']."</h4>");
print_r("<h4>Licensed Beds: ".$modalresults['lic_beds']."</h4>");
print_r("<h4>Net Patient Revenue: "."\$".number_format($modalresults['net_patient_rev'])."</h4>");
print_r("<h4>Net Income: "."\$".number_format($modalresults['net_income'])."</h4>");
print_r("<h4>Discharges: ".number_format($modalresults['disc'])."</h4>");
print_r("<h4>Patient Days: ".number_format($modalresults['pat_days'])."</h4>");
print_r("<h4>ADC: ".sprintf("%.1f",$adc)."</h4>");
print_r("<h4>ALOS: ".sprintf("%.1f",$alos)." Days</h4>");
print_r("<h4>Total Charity and Uncompensated Care Costs: ".$charity_disp."</h4>");
print_r("<hr/ style='width: 100%; color: black; height: 1px; background-color:black;'>");
print_r("<h4><b>Payer Mix (Discharges):</b></h4>");
print_r("<h4>Medicare: ".sprintf("%.1f%%", ($modalresults['medicare']/$modalresults['disc']) * 100)." </h4>");
print_r("<h4>Medicaid: ".sprintf("%.1f%%", ($modalresults['medicaid']/$modalresults['disc']) * 100)." </h4>");
print_r("<h4>All Other: ".sprintf("%.1f%%", $all_other)." </h4>");
print_r("<hr/ style='width: 100%; color: black; height: 1px; background-color:black;'>");
/*print_r("<h4>Urban/Rural Code: ".$modalresults['urban_or_rural']."</h4>");
print_r("<h4>Ownership Type: ".$modalresults['ownership_type']."</h4>");*/
print_r("<h4>State: ".$modalresults['state']."</h4>");
print_r("<h4>City: ".$modalresults['city']."</h4>");
print_r("<h4>Street: ".$modalresults['street']."</h4>");
print_r("<h4>Zip: ".$modalresults['zip']."</h4>");
print_r("<h4>County: ".$modalresults['county']."</h4>");
?>