0

I have an array collection which store data more than 100.000 records, which need to be pass throw webAPI using JSON, but the is server returning a 500 error. When I pass only a few 100 records, it is working fine.

What is alternative to it or any other way to do it?

Below is the example:

DataGoesHere=[]; //This array has more than 100.000 records
var pageUrl = "/Controller/Method";
                let inputData = {
                    'data': DataGoesHere,
                    'arguments': { arguments list } 
                };
                $.ajax({
                    type: 'POST',
                    contentType: 'application/json; charset=utf-8',
                    url: pageUrl,
                    data: JSON.stringify(inputData),
                    dataType: "json",
                    success: function (msg) {

                    }
                });

After I execute this, API is not calling and firing 500 error.

Ronan Boiteau
  • 9,608
  • 6
  • 34
  • 56
Nakul
  • 137
  • 1
  • 11
  • 2
    What is `1 lakh`? Is it a problem for you to batch the requests? Is there more detail on the 500 error (ie, can you check what is the real problem) – Icepickle Oct 11 '18 at 07:48
  • You might find the answer here: https://stackoverflow.com/questions/6154989/maximum-size-of-an-array-in-javascript – ajay datla Oct 11 '18 at 07:52
  • You might find your answer: https://stackoverflow.com/questions/6154989/maximum-size-of-an-array-in-javascript – ajay datla Oct 11 '18 at 07:55
  • Array size no problem, but the problem is passing that array to webAPI is not taking as I convert it to JSON. – Nakul Oct 11 '18 at 07:56
  • Icepickle : only 500 error is showing in console tab. – Nakul Oct 11 '18 at 08:01
  • Alright, but the data is sending, so it's not really a problem with the stringify method, neither for posting the data. It could be that your request is simply exceeding the limits of the post size, or that other problems occur on your server. Without knowing more on the implementation of the server, I think this question is hard to answer – Icepickle Oct 11 '18 at 08:10
  • Does your server have a `maxRequestLength` or `maxAllowedContentLength` setting in the config file which you might be exceeding with your large request? If so, maybe you can increase those settings. – Brian Rogers Oct 11 '18 at 16:10
  • Request is not going to server, I mean there no post back happening, It is MVC project. And when I try to send request, it directly fired 500 error that means parameters are matching. But when I send less data using same method is working fine, but for huge data 500 error. There is no description of error too. – Nakul Oct 15 '18 at 05:36

1 Answers1

0

There are some alternative libraries you can try:

  1. https://github.com/MaiaVictor/LJSON
  2. https://github.com/jed/lave
  3. https://github.com/yahoo/serialize-javascript
  4. https://github.com/benjamn/arson

You can find more libraries to replace JSON.stringify here: https://gist.github.com/stereobooster/b2c9c543e794f3b927f82271b344ec72

Gianpaolo Papa
  • 458
  • 4
  • 9
  • No third party libraries, can we do it with self code? – Nakul Oct 11 '18 at 08:00
  • I don't know if native **toString()** function could be a solution for you. It will convert the array to a comma separed string, then you can put this as string into your _inputData_ object. – Gianpaolo Papa Oct 11 '18 at 08:07
  • Or using join to create a json-like string: `DataGoesHere = '["'+DataGoesHere.join('", "')+'"]';` – Gianpaolo Papa Oct 11 '18 at 08:11
  • 1
    The problem is not with the stringification, but rather with how the server handles the response (otherwise there wouldn't be a 500 error, but it would simply be a javascript error). I don't really see what the answer brings as a value to the question at hand – Icepickle Oct 11 '18 at 08:11
  • 1
    Gianpaolo, your suggestion is makes sense and good to implement. Letter can be converted to dictionary array using c# code. I will try this. – Nakul Oct 11 '18 at 09:27