0

我有一个函数可以在一个变量中获取两个数组并像这样创建 json

function get_categories_n_subs_by_id($id){ ///this is category id;
    header('Content-type: application/json');
    $data['categories'] = $this->categories_model->get_categories_by_id($id);
    $data['sub_categories'] = $this->sub_categories_model->get_sub_categories_by_cat_id($id);
    echo json_encode($data);
}

这段代码运行良好,但是当我重新启动我的电脑时,json 没有响应。

之前的反应还好,是这样的

{
  "categories":{
    "fld_id":"106",
    "fld_value":"some value",
    "fld_price":"0.00",
    "fld_attribute_id":"16",
    "fld_parent_id":"0" 
  },
  "sub_categories":[{
    "fld_id":"107",
    "fld_value":"some sub values",
    "fld_price":"0.00",
    "fld_attribute_id":"16",
    "fld_parent_id":"106"
   }]
}

但现在没有回应。这个函数的 json 调用是:

var url = base_url+"admin/categories_controller/get_categories_n_subs_by_id/"+id;
    $.getJSON(url, {ajax:1}, function(data){
        var id = data['categories']['fld_id'];
        var name = data['categories']['fld_name'];
        var description = data['categories']['fld_description'];
        //var status = data['fld_status'];

        $("#new_category #name").attr('value',name);
        $("#new_category #description").html(description);
        $("#new_category #category_id").attr('value',id);
        var html="";
        if(data['sub_categories'].length==0){
            html = html + 'Sub Categories: <input type="text" id="sub_name[]" name="sub_name[]" maxlength="40"  value=""/>'+
                        ' Description: <textarea id="sub_description[]" name="sub_description[]"></textarea>'+
                        '<input type="hidden" id="sub_cat_id[]" name="sub_cat_id[]" value="">'+
                        '&nbsp;&nbsp;&nbsp;&nbsp;'+
                        '<a href="javascript:void(0);" class="add_attribute_values" onclick="add_sub_categories(this.name);" name="sub_cat_0">[+]</a>&nbsp;&nbsp;<br/>';
        }
        $.each(data['sub_categories'], function(index, array) {
            var id = array['fld_id'];
            var name = array['fld_name'];
            var description = array['fld_description'];
            html = html + 'Sub Categories: <input type="text" id="sub_name[]" name="sub_name[]" maxlength="40"  value="'+name+'"/>'+
                        ' Description: <textarea id="sub_description[]" name="sub_description[]">'+description+'</textarea>'+
                        '<input type="hidden" id="sub_cat_id[]" name="sub_cat_id[]" value="'+id+'">'+
                        '&nbsp;&nbsp;&nbsp;&nbsp;'+
                        '<a href="javascript:void(0);" class="add_attribute_values" onclick="add_sub_categories(this.name);" name="sub_cat_0">[+]</a>&nbsp;&nbsp;<br/>';
        });
        //alert(html);
        $("#sub_cat_0").html(html)
    });

在我重新启动我的电脑之前一切都是正确的,但在那之后,当我检查萤火虫时,json 没有响应。响应是空的...请帮我解决这个错误...

4

1 回答 1

0

问题已解决..在重新启动我的电脑之前,我使用的 IP 地址如下:

http://192.168.1.2

重新启动后我正在使用

http://localhost

在我配置的codeigniter配置文件中,http://192.168.1.2它影响了json......所以你们在这样做时要记住它......

于 2013-05-07T06:50:04.223 回答