-1
我有以下PHP函數:jQuery的passdata PHP數據進行可變
public function get_dataset() {
$dataset = "[";
$data_set = $this->operations_model->get_date();
foreach ($data_set as $value) {
$date = $value['date'];
$date = strtotime($date);
$dataset .= '[' . $date . ',' . $value['revenue'] . '],';
}
$dataset = substr($dataset, 0, -1);
$dataset .= "]";
echo $dataset;
}
從數據庫查詢返回的數據集,返回的數據是按以下格式:
[[1433163200,15000],[1433163200,5800],[1433163200,5800],[1433163200,5800],[1435150400,15000],[1433163200,5800],[1433163200,5800],[1433336000,5800],[1433163200,5800],[1433163200,15000],[1435755200,5800],[1435755200,5800],[1435755200,5800],[1435755200,5800],[1435755200,5800],[1441976000,15000],[1441976000,5800],[1441976000,5800],[1441976000,5800],[1435755200,5800],[1438433600,5800],[1438433600,5800],[1438433600,15000],[1438433600,5800],[1438433600,5800],[1438433600,15000],[1438433600,5800],[1438433600,5800],[1438433600,5800],[1438433600,15000],[1441112000,5800],[1441112000,5800],[1441112000,5800],[1441112000,15000],[1441112000,5800],[1443704000,5800],[1443704000,5800],[1443704000,5800],[1443704000,15000],[1443704000,5800],[1444742133,5800],[1444742133,5800],[1444742133,5800],[1444742133,5800],[1444742510,15000],[1444742510,5800],[1444742510,5800],[1444742510,5800],[1444742510,5800],[1444742510,5800],[1444742510,5800],[1444742510,5800],[1444742518,15000],[1444742518,5800],[1444742518,5800],[1444742518,5800],[1444742518,5800],[1444742518,5800],[1444742518,5800],[1444742518,5800],[1444742671,15000],[1444742671,5800],[1444742671,5800],[1444742671,5800],[1444742671,5800],[1444742671,5800],[1444742671,5800],[1444742671,5800],[1444742671,5800],[1444742671,5800],[1444743338,5800],[1444743338,15000],[1444743489,5800],[1444743489,15000],[1444743551,5800],[1444743551,15000],[1444743639,5800],[1444743639,15000],[1444743749,5800],[1444743749,15000],[1444743810,5800],[1444743810,15000],[1444743900,15000],[1444743920,15000],[1444743949,15000],[1444744037,15000],[1444744104,5800],[1445251070,5800],[1445251070,15000],[1445251080,5800],[1445251080,15000],[1445251085,5800],[1445251085,15000]]
我會喜歡將此數據傳遞給一個jQuery變量,以便以下面的語法返回:
var data = [
[1325365200000, 17],
[1325451600000, 74],
[1325538000000, 6],
[1325624400000, 39],
[1325710800000, 20],
[1325797200000, 85],
[1325883600000, 7]
];
In aj查詢變量。我試過以下內容:
var revenue = ["<?php echo base_url(); ?>operations/get_dataset"];
但它不起作用,請告訴我做錯了什麼?
您可以在視圖加載時傳遞變量/使用AJAX,而是在頁面加載/動態後加載數據。 –
直接從瀏覽器運行'get_dataset()',並檢查你到達的數據? –
你什麼時候調用這個函數? –