发送多维对象 - >最后一部分丢失
I'm sending a multidimensional object with an ajax post request but some times the last part of the object is lost? Is there some kind of limit to how much data you can send?
--------
update
when counting the childs in data.accounts
before the ajax post the number is 221, and when counting the data.accounts
in the success handler the number is still 221
The data being sent is at the most 10kb
When I do this right before the object is sent with ajax, all data is represented
var arr = [];
for(var key in obj){
arr[arr.length] = key+' = '+obj[key];
}
alert(arr.join('
'));
But when doing this on the backend the last part of the data is lost
print_r($data);
data structure (there are over 200 childs in data.accounts
but only 198 are recieved)
Array
(
[account_id_] => 0
[name] => 1
[type] => 2
[type_pl] => Drift
[type_b] => Status
[type_p] =>
[type_h] => Tekst
[type_t] => Sum
[att_sumfrom] => 4
[vatcode] => 3
[accounts] => Array
(
[0] => Array
(
[account_id_] => 1
[name] => OMS�TNING
[type] => 3
[att_sumfrom] =>
[vatcode] =>
)
[1] => Array
(
[account_id_] => 1000
[name] => Varesalg
[type] => 0
[att_sumfrom] =>
[vatcode] => S25
)
[2] => Array
(
[account_id_] => 1200
[name] => Udf�rt arbejde
[type] => 0
[att_sumfrom] =>
[vatcode] => S25
)
.......
Sending the data
this.send = function(){
var jqxhr = $.ajax({
url : this.url,
data : this.data,
timeout : this.no_timeout ? 0:this.timeout,
cache : this.cache,
dataType : this.dataType,
type : this.type,
global : this.global
})
There is a limit to how much data you can send per request, and depending on what method you're using. If you're using POST
in PHP as the backend, take a look at PHP.ini memory_limit
and post_max_size
, where the former is script memory hogging and the latter is how much data can be sent through post requests. Defaults are 128M and 8M respectively.
If you're sending too much data that the server is not allowed to handle, the data will be cut as per instructions.
Update
It is hard to debug without all the relevant code. Are you doing anything else on the backend before printing the array or are you just print_r($_POST['data'])
ing? Because if you're not doing anything else, it still sounds like a memory setting on the server.
Anecdote
I remember a project where I had about 400 rows of data, each row had 7 columns (lots of text) that I sent through an AJAX object, and ~70 of the last rows was just cut out. After doubling the post_max_size
all the data was being sent properly.
This may or may not be related to your problem, but rather than attaching array items based on the array length, you should use the "push" function, which adds an item to the end of an array:
for(var key in obj){
arr.push(key+' = '+obj[key]);
}