簡體   English   中英

我的伺服器傳回空白頁面,角落里有「null」

[英]My server returns blank page with 'null' in the corner

我需要簡單的Web服務才能從本地數據庫獲取數據,但是當我將文件從測試服務器移到實際服務器時,我只收到空白頁面,左上角帶有“空”。 我的PHP代碼很簡單:

<?php
// Include config
require_once 'config/db.php';
$sql = new db();
$conn = $sql->connect();

$task = isset($_GET['task']) ? mysql_real_escape_string($_GET['task']) :  "";

if(!empty($task))
{
    if($task === "totals")
    {
        $qur = mysql_query("working query - no problem here;");
        $result =array();
        while($r = mysql_fetch_array($qur))
        {
            extract($r);
            $result[] = array("total_value" => $total_value, 'orders_date' => $orders_date, 'number_of_orders' => $number_of_orders); 
        }
        $json = $result;
    }
}

@mysql_close($conn);

/* Output header */
header('Content-type: application/json');
echo json_encode($json, JSON_PRETTY_PRINT);
?>

這是db.php代碼:

<?php
class db
{
    // Properties
    private $dbhost = 'ip-address';
    private $dbuser = 'xxx';
    private $dbpass = 'yyy';
    private $dbname = 'zzz';
    // Connect
    public function connect()
    {
        $conn = mysql_connect($this->dbhost, $this->dbuser, $this->dbpass);
        mysql_select_db($this->dbname, $conn);
    }
}
?>

可能是Json_encode沒有給出正確答案。

1)另外,請確保JSON_PRETTY_PRINT僅適用於PHP版本JSON_PRETTY_PRINT 它的值為128,因此嘗試用128替換JSON_PRETTY_PRINT。

僅在頁面頂部的錯誤報告上進行調試

2)還要確保在編碼之前嘗試打印$json

3)如注釋中所述,僅在實際獲取數據時才進行編碼

!empty($json){
header('Content-type: application/json');
echo json_encode($json, JSON_PRETTY_PRINT);
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM