【问题标题】:Unknown/Unhandled Data Type(s)未知/未处理的数据类型
【发布时间】:2016-07-05 05:26:03
【问题描述】:

请帮忙。

我正在为我的网站使用 codeigniter/php。它在我的本地主机中运行良好,但是当我尝试将其转移到 live 时,它​​出现了错误。在我试图解析 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>");

希望这足以解释我的问题。谢谢

【问题讨论】:

    标签: php jquery json codeigniter


    【解决方案1】:

    使用 echo 而不是 return ,在 ajax 中我们得到输出

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-03
      • 1970-01-01
      • 2016-05-28
      • 2020-09-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多