I have a problem with which I am unsure how to deal with:
I have recovered a big JSON from an API, whose contents I need to show in my website (all ok here), but I need to return the current data shown in the website (it can be deleted, edited and modified before being sent back through my AJAX call), so that I can add that data to another website, also through an API.
I can recover and add without problems with my current logic, the problem comes when I get a big JSON from my AJAX call:
$.post('ajax/send_data.php?command=create&id=' + id, {data: superArray}, function(response){
$('#data_table').html(response);
});
Even if I send my data like this, the max. capacity is exceeded, which results in the creation of around 30 rows of data. Changing the max_input_vars in php.ini isn't an option, I can't change those myself, plus it should be set to a really big number to fit, or have no limit...
The only solution that comes to my mind (after several others that aren't applicable to my situation) is to loop over the "array", sending the data in chunks with multiple $.post calls...
The problem is that my "array" is not an array, as php sends back an object, being it originally an associative array.
The question is... how can I loop over my object, divide into chunks, and send back to PHP through AJAX those chunks?
Here's what I was trying, using as reference Convert and Loop through JSON with PHP and JavaScript Arrays/Objects
for (var key in superArray) {
str += JSON.stringify(superArray[key]);
cnt++;
if(cnt % 25 == 0){
console.log(str);
temparray = JSON.parse(str); // here gives an error
$.post('ajax/send_data.php?command=create&id=' + id, {data: temparray}, function(response){
str = "";
});
}
}
I can't turn back my string chunks into an object, as the key is lost in the process (Each data is created like:
undefined{ "id":"1338", "name":"24HRS ", "description":"..." })
What am I doing wrong here? is there maybe a better approach to my problem that I am maybe not aware of?
Edit:
That's what I send back from my Ajax call:
echo json_encode($html);