json_encode()值传播的格式不正确

json_encode()值传播的格式不正确,json,ajax,codeigniter,Json,Ajax,Codeigniter,我使用json_encode函数在ajax响应中获取值 $product_id = $this->input->get('product_id'); if ($data = $this->sales_model->getProductById($product_id)) { //$product_id = $data->id; $product_name = $data->name;

我使用json_encode函数在ajax响应中获取值

$product_id = $this->input->get('product_id');
        if ($data = $this->sales_model->getProductById($product_id)) {
            //$product_id     = $data->id;
            $product_name   = $data->name;
            $product_unit   = $data->product_unit;
            $sales_price    = $data->sales_price;
            $product_details = array('product_id' => $product_id, 'product_name' => $product_name, 'product_unit' => $product_unit, 'sales_price' => $sales_price);
            //add the header here
            header('Content-Type: application/json');
            echo json_encode($product_details);
        }
然后在本地服务器中获取值作为

Object {product_id: "77", product_name: "Testdescription", product_unit: "", sales_price: "120.00"}
但当我上传到服务器,然后我们并没有得到任何回应

ajax调用函数:

 $.ajax({
                type: "get",
                url: "index.php?module=sales&view=getproductinfo",
                dataType: "json",
                contentType:"application/json",
                data: {product_id: data_id},
                error: function() {
                    $('#info').html('sss');
                },
                success: function (response) {
                    console.log(response);
}
});

maybee您可以使用../index.php?module=sales&view=getproductinfo,并在error console.log(respon)上使用要解决您的问题

您已检查您在产品id中发送的数据id是否正确传递。如果未传递,则响应将为空,不会出现任何错误。

首先检查您的基本url。首先通过执行console.log(url)检查您的“url”。无论你是否得到正确的网址。似乎无法正确获取服务器url。
url:“/index.php?module=sales&view=getproductinfo”,