如何将大数组值从javascript传递到php

如何将大数组值从javascript传递到php,javascript,php,arrays,Javascript,Php,Arrays,我的要求是发出多个xml请求并将数据存储在一个数组中,这样,如果我得到例如4000条记录,我就可以在一个页面中显示40条记录,并可以进行分页。因此,如果转到第2页,我可以从数组中获取数据,而不是再次发出xml请求 目前,我正在使用一个php数组变量来存储大量数据,单击一个按钮,javascript函数将使用ajax请求通过查询字符串再次调用相同的php页面。问题是查询字符串不能容纳大型数组 这是我的密码- 将php数组传递给javascript变量 echo '<script type="

我的要求是发出多个xml请求并将数据存储在一个数组中,这样,如果我得到例如4000条记录,我就可以在一个页面中显示40条记录,并可以进行分页。因此,如果转到第2页,我可以从数组中获取数据,而不是再次发出xml请求

目前,我正在使用一个php数组变量来存储大量数据,单击一个按钮,javascript函数将使用ajax请求通过查询字符串再次调用相同的php页面。问题是查询字符串不能容纳大型数组

这是我的密码-

将php数组传递给javascript变量

echo '<script type="text/javascript">/* <![CDATA[ */';
echo 'var allProd = '.json_encode($allProd);
echo '/* ]]> */</script>';
我尝试使用隐藏的表单变量,但即使是$\u POST也不接受大数组。你们谁能给我一个解决方案或建议吗。这将对我很有帮助


即使将数据存储在数据库或会话变量中也不能解决我的需求。因为如果我使用数据库,我无法检索多个查询的数据,如果用户对同一url使用多个选项卡,甚至php会话变量都将被覆盖。

我也遇到过类似的情况,我将数兆数据从Javascript传递到php

我没有代码,所以我只能给你一个p代码解决方案,但它会给你一个想法

// JavaScript:

var bigstring = "...."; the data to pass
var chunkSize = 100*1024; 

// http://stackoverflow.com/questions/7033639/javascript-split-large-string-in-n-size-chunks
var chunks = splitString(bigstring);

var chunkIdx = -1; // Prime the pump

function sendNextChunk() {
  chunkIdx++;


  if (chunkIdx < chunks.length) {
    // Your AJAX call here
    var data = {
      piece: chunkIdx
      ofpieces: chunks.length;
    }

    // set your onsuccess method to call
    // sendNextChunk again
  }
}

sendNextChunk(); // start it.

POST可以处理大量数据。根据您的平台,您可以将大小限制设置为合理的值。
<script>
function get_results(PageNo, SelIndex, totPage, totEnt, allProd)
{
var allProd1 = '';
for (i=0; i < allProd.length; i++)
{
    allProd1 += '&q[' + i + ']=' + encodeURIComponent(JSON.stringify(allProd[i]));
}

if (PageNo > totPage || isNaN(PageNo))
{
    alert ('Please enter the available pages');
}
else
{
var neggProd = sessionStorage.getItem('Product1');
var cntryCode = sessionStorage.getItem('Cntry'); 
var sortType;
var ordType;
if (SelIndex == 0) {sortType = 'bestmatch';}
else if (SelIndex == 1) {sortType = 'bestseller';}
else if (SelIndex == 2) {
    sortType = 'pricehigh';
    ordType = 'dsc';
}
else if (SelIndex == 3) {
    sortType = 'pricelow';
    ordType = 'asc';
}

document.getElementById("sl_api").innerHTML="";
document.getElementById("sl_api1").setAttribute("style","background:     url('KartEazy/loading.gif') #edeeee no-repeat center center; background-size:20px 20px;");

if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("sl_api").innerHTML= xmlhttp.responseText;
    }
  }

xmlhttp.open("GET",'KartEazy/Skimlinks/Skimlinks.php?PageNum=' + PageNo + '&neggProd=' + neggProd + '&cntryCode=' + cntryCode + '&sortType=' + sortType + '&ordType=' + ordType + '&totEnt=' + totEnt + allProd1, true);
xmlhttp.send();
setInterval(function()    {
document.getElementById("sl_api1").setAttribute("style","background: #edeeee;")},4500);
}
}
</script>
if(isset($_REQUEST['q']))
{
$totEnt = $_REQUEST['q'];
}
// JavaScript:

var bigstring = "...."; the data to pass
var chunkSize = 100*1024; 

// http://stackoverflow.com/questions/7033639/javascript-split-large-string-in-n-size-chunks
var chunks = splitString(bigstring);

var chunkIdx = -1; // Prime the pump

function sendNextChunk() {
  chunkIdx++;


  if (chunkIdx < chunks.length) {
    // Your AJAX call here
    var data = {
      piece: chunkIdx
      ofpieces: chunks.length;
    }

    // set your onsuccess method to call
    // sendNextChunk again
  }
}

sendNextChunk(); // start it.
// Read in each chunk, and the piece number.
// The way I've got the code written, then come in sequentional order
// so open up a temporary file and append the data.
// when piece === ofpieces
// you have the whole file and you can then process it.