简体   繁体   中英

Post php array to using .post in javascript/jquery

How can I change the following get request to a post in 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();
});

The array is very large and I need a more efficient way to pass the array.

If you already have the data on the server side, why pass it back to the server from the client?

A get request cannot be that big, try doing a POST request instead.

$.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');

should do

You need to use a $.post (or a $.ajax ) method instead of $.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');

Of course this is assuming the resource is hosted on the same URL, and that you do not need JSONP. If you are using JSONP, you cannot POST data (unless the server supports CORS).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM