我查詢數據庫我在我的模型,像這樣笨 - 發送JSON腳本文件
function graphRate($userid, $courseid){
$query = $this->db->get('tblGraph');
return $query->result();
}
我控制器從我的模型中獲取數據回來,我JSON編碼它像這樣
if($query = $this->rate_model->graphRate($userid, $courseid)){
$data['graph_json'] = json_encode($query);
}
$this->load->view('graph', $data);
而這就是返回我像這樣
[
{"id":"1","title":"myTitle","score":"16","date":"2013-08-02"},
{"id":"2","title":"myTitle2","score":"17","date":"2013-09-02"},
{"id":"3","title":"myTitle3","score":"18","date":"2013-10-02"}
]
一個JSON對象,在我看來,圖我加載一個js文件
<script type="text/javascript" src="script.js"></script>
現在我想使用$數據從我的控制器發送到我的視圖,我的外部script.js使用 labels and data餵我的圖表。但是,如何將Json數據傳遞給我的外部script.js,以便我可以使用它?有關JSON數據
1件事,是不是有可能得到JSON數據的輸出作爲
{
"obj1":{"id":"1","title":"myTitle","score":"16","date":"2013-08-02"},
"obj2":{"id":"2","title":"myTitle2","score":"17","date":"2013-09-02"},
"obj3":{"id":"3","title":"myTitle3","score":"18","date":"2013-10-02"}
}
由於這些信息,我明白了我必須做的! – mXX