简体   繁体   English

将php数组发布为在javascript / jquery中使用.post

[英]Post php array to using .post in javascript/jquery

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

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请求。

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

Of course this is assuming the resource is hosted on the same URL, and that you do not need JSONP. 当然,这是假设资源托管在同一URL上,并且您不需要JSONP。 If you are using JSONP, you cannot POST data (unless the server supports CORS). 如果使用JSONP,则无法发布数据(除非服务器支持CORS)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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