[英]Post php array to using .post in javascript/jquery
如何將以下get請求更改為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();
});
數組很大,我需要一種更有效的方法來傳遞數組。
如果您已經在服務器端擁有數據,為什么還要將其從客戶端傳遞回服務器?
獲取請求不能太大,請嘗試執行POST請求。
$.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');
應該做
您需要使用$.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,則無法發布數據(除非服務器支持CORS)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.