0

Angular.js

$scope.exportTable = function (param, isId) {
    //var excelContents = JSON.stringify( $((isId) ? "#"+param:"."+param).html());
    console.log(JSON.stringify($((isId) ? "#" + param : "." + param).html()));
    $interval($scope.downloadExcel(JSON.stringify($((isId) ? "#" + param : "." + param).html())), 3000);
};


$scope.downloadExcel = function (excelContents) {
    console.log("this should be displayed after 3 seconds");
    $.ajax({
        url: urls.BASE_API + "user/setExcelContents",
        data: {excelContents: excelContents},
        type: 'POST',
        dataType: 'json',
        complete: function (data) {
            if (data.responseText == "1") {
                window.location.href = urls.BASE_API + "user/exportExcel";
            }
        }
    });
};

Here I'm trying to send 1600 table rows to a controller method in Java, which then I will catch the param with @RequestParam('excelContents') This throws error on Request parameter is not present

Now, If i send like 20-50 table rows, this works fine without any errors.

I was thinking that JSON.stringify() can't complete its task BEFORE I send it as the parameter, so thats why I added the $interval, but $interval doesn't work. it doesn't pause for 3 seconds (3000 milliseconds) when I pass the argument. The method runs as soon as I call it, without any pausing.

Butiri Dan
  • 1,759
  • 5
  • 12
  • 18
  • 1
    `JSON.stringify` 100000% guaranteed completes its task before `downloadExcel` is called, that is how method invocations and usage of their return values work, there is nothing async about `JSON.stringify`, the method has to return for the runtime to use its result to call the next method. What does the `console.log` show you? How big is the data you are trying to send along? https://stackoverflow.com/questions/2880722/can-http-post-be-limitless/55998160#55998160 – luk2302 Jul 23 '19 at 13:23
  • @luk2302 It's 3.9MB – tornikeShelia Jul 23 '19 at 13:27
  • This is really weird , because it works when I try to send 50 rows , but suddenly the parameter isn't there when I send 1600 – tornikeShelia Jul 23 '19 at 13:29
  • I just found that after 1200 records, the Parameter stops working. What might be the problem ? How can I avoid this ? – tornikeShelia Jul 23 '19 at 13:55
  • E.g. might be that 2MB is the limit. – luk2302 Jul 23 '19 at 13:56

0 Answers0