简体   繁体   English

AJAX POST数据未完全发送到服务器

[英]AJAX POST data not being completely sent to server

I'm uploading a CSV (65KB) through a form on my site, parsing it with papaparse and then POSTing it with ajax to my server: 我正在通过网站上的表单上传CSV(65KB),用papaparse解析它,然后用ajax将其发布到我的服务器:

console.log(csv)
// if everything is ok, send via AJAX to process with PHP
$.ajax({
    type: "POST",
    url: "scripts/batch_objects.php",
    dataType: 'json',
    data: {'Data': csv},
    success: function(result){
        $("#batchResult").html(result);
    },
    error: function(result) {
        $("#batchResult").html(result);
    },
});

In the console, I can see that the CSV is properly uploaded and parsed - it confirms that all the rows (435 of them) are set in the csv var. 在控制台中,我可以看到CSV已正确上传和解析-确认所有行(其中的435条)均已在csv var中设置。 On the server side I've got a quick script to check things out: 在服务器端,我有一个快速脚本来检查内容:

<?php
    $csv = $_POST['Data'];
    echo count($csv);
?>

However on the server side I'm only getting 143 of the rows (the output of the echo statement), instead of all 435. 但是在服务器端,我只得到143行(echo语句的输出),而不是全部435。

I've tried setting php_value post_max_size 20M in my .htaccess but that hasn't helped. 我已经尝试在.htaccess中设置php_value post_max_size 20M ,但这并没有帮助。

The following fixed things for me (found inspiration here ): 以下内容对我来说是固定的(在这里找到了灵感):

// get our data together
var postData = {};
postData.Table = table;
postData.Action = action;
postData.Data = csv;

// if everything is ok, send via AJAX to process with PHP
$.ajax({
    type: "POST",
    url: "scripts/batch_objects.php",
    contentType: "application/json",
    data: JSON.stringify(postData),
    success: function(result){
        $("#batchResult").html(result);
        console.log("Success " + result);
    },
    failure: function(result) {
        $("#batchResult").html('ERROR: ' + result);
        console.log('Eror ' + result);
    },
});

Then on the sever side you can access the POST data with: 然后在服务器端,您可以使用以下命令访问POST数据:

$post_data = json_decode($HTTP_RAW_POST_DATA);

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

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