我已经从JSON数组创建了一个表(用于数据表),并且我在数组中嵌入了一个链接,该链接有一个ID(来自mysql表的主键),然后它应该触发动态模式提取更多信息。嵌入在JSON中的特定行如下所示:
PHP中的:
$results['provider_name'] = "<a id='".$results['id']."' data-toggle='modal' href='#provmodal' class='push'>".$results['provider_name']."</a>";
但在JSON中,提供者名称字段如下所示:
"provider_name":"COTTAGE GROVE COMMUNITY HOSPITAL<\/a>"
这样做的副作用是当我在页面上回显它时,它会使剩余的JSON成为链接。这似乎不会影响页面上的显示。
当生成表格单元格时,它包含id="#"
以及模态触发器信息和成功触发我的模态的class="push"
,但其中没有任何信息让我相信它没有从线路接收ID并触发success:
功能。
这是完全生成的表格单元格的样子:
<a id="96" data-toggle="modal" href="#provmodal" class="push">COTTAGE GROVE COMMUNITY HOSPITAL</a>
这是模态的ajax脚本 - &gt;
$(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');
});
}
});
});
});
单击模态触发器时, console.log()
没有返回任何内容,因此我知道它没有从id
属性接收它。
我是否在json中正确嵌入了我的链接?
我有点困惑,因为我实际上有这个脚本在另一个页面上工作,唯一的区别是它不是外部ajax json源。我正在页面上生成json数组并将其回显为数据表'aaData'的javascript变量并以此方式填充表。我更喜欢从外部请求json,这就是我遇到这个问题的地方。
:编辑:
这里是modalquery_providerlist.php按要求 - &gt;
<?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>");
?>