0
我正在使用下面提到的代碼(get_data.php)將JSON數據發送到AJAX調用。我想包含相同的PHP文件來獲得計數($ ret)。 當我包含這個文件無法獲得計數($ ret),但文件被強制下載。 如果我刪除「header(」Content-type:text/json「);」它的工作原理,但我會需要它發送JSON響應。任何人都可以幫助我避免強制下載此文件時,包括?防止強制下載
get_data.php:
<?php
header("Content-type: text/json");
include('connect.php');
global $conn;
$site_id = $_GET['site_id'];
$dbh = $conn->prepare('SELECT UNIX_TIMESTAMP(current_ts), response_time FROM site_response WHERE current_ts >= DATE_SUB(NOW() , INTERVAL 30 MINUTE) AND site_id ='.$site_id.'');
$dbh->bindParam(':site_id', $site_id);
$dbh->execute();
$graph_data = $dbh->fetchAll();
$ret = array();
foreach($graph_data as $data)
{
$current_time = $data['UNIX_TIMESTAMP(current_ts)']*1000;
$response_time = $data['response_time']*1;
$ret[] = array($current_time, $response_time);
}
echo json_encode($ret);
?>