2013-05-07 117 views
0

我有獲取一個變量兩個數組,創造這樣JSON對象在PHP沒有返回

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,但是當我重新啓動我的電腦沒有從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響應,而我通過Firebug的檢查。響應就是一句......請幫助我這個錯誤...

+0

PC重啓不影響,只需使用error_reporting檢查螢火蟲(1) – Shin 2013-05-07 06:37:55

+0

如何重新啓動您的電腦會影響服務器上發生的情況? – Barmar 2013-05-07 06:42:04

+2

@Barmar:好吧,這取決於「服務器」在哪裏運行。一些開發者在'localhost'上工作... – akira 2013-05-07 06:43:50

回答

0

的問題out..before重新啓動我的電腦排序我所用的IP地址,如:

http://192.168.1.2 

並重新啓動後我使用

http://localhost 

和我已經配置爲http://192.168.1.2了影響JSON笨配置文件...所以你們記住它,而這樣做......