doupu7651 2015-10-21 14:59
浏览 109

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

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:

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. 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.

I've tried setting php_value post_max_size 20M in my .htaccess but that hasn't helped.

  • 写回答

1条回答 默认 最新

  • drxzpo70788179614 2015-10-21 18:46
    关注

    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_data = json_decode($HTTP_RAW_POST_DATA);
    
    评论

报告相同问题?

悬赏问题

  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?