2016-07-05 82 views
0

請幫忙。未知/未處理的數據類型

我爲我的網站使用codeigniter/php。它在我的本地主機上運行良好,但是當我嘗試將其轉移到現場時,它出現錯誤。在我的腳本中檢測到錯誤部分,我試圖解析在php中生成的json。這是那裏的JSON編碼:

function get_product_offered_json(){ 

    $data = []; 
    $query = $this->db->get("product_smb"); 

    if ($query->num_rows() > 0){ 
     foreach ($query->result() as $row) { 
      $data[] = $row;     
     } 
     return json_encode($data); 
    }else{ 
     return "empty"; 
    } 

} 

,這是我分析它:

jQuery.post(base_url + "/product/smb/get_product_offered_json/", function(data, status){ 

       if (data != "empty"){ 

        //productOffered.prop("disabled", false); 

        var $data = jQuery.parseJSON(data); 

        productOffered.empty(); 
        productOffered.append("<option value='0'>Please choose here...</option>"); 

希望這足以說明我的問題。感謝

回答

1

的使用echo代替return,在阿賈克斯我們得到的輸出

if ($query->num_rows() > 0){ 
    foreach ($query->result() as $row) { 
     $data[] = $row;     
    } 
    echo json_encode($data); 
}else{ 
    echo "empty"; 
}