2013-11-15 31 views
0

如何將以下獲取請求更改爲jquery中的帖子?將php數組發佈到javascript中使用.post/jquery

$.getJSON('chartHelperphp?start=' + Math.round(e.min) + 
    '&end=' + Math.round(e.max) + 
    '&callback=?&array=<?php echo json_encode($data); ?>', function (data) { 
    chart.series[0].setData(data); 
    chart.hideLoading(); 
}); 

該數組非常大,我需要一個更有效的方式來傳遞數組。

回答

0

如果您已經擁有服務器端的數據,爲什麼要從客戶端將其傳回服務器?

一個獲取請求不能是那個大,反而嘗試做一個POST請求。

0
$.post('chartHelperphp?start=' + Math.round(e.min) + 
    '&end=' + Math.round(e.max) + 
    '&callback=?&array=<?php echo json_encode($data); ?>', function (data) { 
    chart.series[0].setData(data); 
    chart.hideLoading(); 
} , 'json'); 

應該做

+0

這還是要做一個請求... – qwertynl

0

你需要使用一個$.post(或$.ajax)方法,而不是$.getJSON

$.post('chartHelperphp', { 
    start: Math.round(e.min), 
    end: Math.round(e.max), 
    array: <?php echo json_encode($data); ?> 
}, function(data) { 
    // do something with data 
}, 'json'); 

當然這是假設資源託管在同一個URL上,並且您不需要JSONP。如果您使用JSONP,則無法POST數據(除非服務器支持CORS)。