我需要显示一个包含来自服务器的一些数据的报告,这还包括一个图表。我试图在表单已经提交后使用 $.getJSON 发送 json 数据,但由于某种原因,我什至无法回显 $_GET [rep] 以确保我收到正确的数据.. 下面是 php 代码,这里是 js http://jsfiddle.net/f8rGb/2/
PHP代码
if (isset($_POST["search"]) and $_POST["search"] == "go"){
$name = $_POST['term'];
$project = new Project();
$pro = $project->get_project($name);
$serv = $project->get_project_service_by_id($pro);
// DOING this to make sure i recieve the variable
// echo $_GET['rep'];
if(isset($_GET['rep']))
die(json_encode($serv));
}
JS代码
function searchProjectsRep() {
// TRIGGERING THIS FUNCTION IN THE ONSUBMIT EVENT OF THE FORM
var datos = $('#formProjectsRepSearch').serialize();
var uri = $('#formProjectsRepSearch').attr('action');
$.ajax({
url: uri,
data: datos,
type: 'POST',
success: function(resp) {
$('#ajaxProjectsRep').html(resp);
projectChart();
}
});
}
// CHART FUNCTION
function projectChart(){
$.getJSON('controller.php?rep=1', function(data) {
options = {
chart: {
renderTo: 'chart_div',
defaultSeriesType: 'pie'
},
title: {
text: 'Datos de proyecto'
},
series: []
};
var statusCount = {},
serie1 = [];
data.forEach(function(e) {
statusCount[e.status] = 1 + (statusCount[e.status] || 0);
});
$.each(statusCount, function(status, count) {
serie1.push( [status, count] );
});
options.series.push({data: serie1});
new Highcharts.Chart(options);
});
}