0

By some reason there's a parsing error with the ajax code below if the service returns more than 4000 lines (everything is correct for less than 4000 lines ). if anyone has a solution for this problem? merci,

                      $.ajax({
                        url: "/service.aspx",
                        type: "post",
                        dataType: "json",
                        data: {
                            dateFrom: strDateFrom,
                            dateTo: strDateTo,
                            visible: ($("#showAll").is(":checked") ? 0 : 1)

                        },
                        success: function (data) {
                            options.success(data);
                            self.lineColor();
                        },
                        error: function (jqXHR, exception) {
                            var msg = '';
                            if (jqXHR.status === 0) {
                                msg = 'Not connect.\n Verify Network.';
                            } else if (jqXHR.status == 404) {
                                msg = 'Requested page not found. [404]';
                            } else if (jqXHR.status == 500) {
                                msg = 'Internal Server Error [500].';
                            } else if (exception === 'parsererror') {
                                msg = 'Requested JSON parse failed.';
                            } else if (exception === 'timeout') {
                                msg = 'Time out error.';
                            } else if (exception === 'abort') {
                                msg = 'Ajax request aborted.';
                            } else {
                                msg = 'Uncaught Error.\n' + jqXHR.responseText;
                            }
                            console.log(msg); //Requested JSON parse failed.
                        }
Jawadovic3814
  • 407
  • 1
  • 4
  • 8
  • 1
    I've received **much** bigger JSON payloads via `$.ajax` than 4,000 lines (well, I guess it depends how long the lines are -- let's just say, **really** big payloads) and never had a problem like that. Have you looked at the result that actually arrives at the browser? I suspect your server is cutting it off (buffering problem, time limit, something like that). – T.J. Crowder Feb 09 '18 at 19:30
  • the browser does not receive anything – Jawadovic3814 Feb 09 '18 at 19:51
  • I'd start by looking at the code in your `service.aspx`. See if there's a server setting or something in your code that cuts off your response data after a certain byte limit. – user9263373 Feb 09 '18 at 19:53
  • 1
    Your comment _"the browser does not receive anything"_ contradicts the problem in your post. Again, I'd start by looking at your code in `service.aspx`. – user9263373 Feb 09 '18 at 19:56
  • thank you, I fixed the problem, I had to change my service: var serializer = new JavaScriptSerializer(); serializer.MaxJsonLength = Int32.MaxValue; – Jawadovic3814 Feb 09 '18 at 21:19
  • @Jawadovic3814:You should post that as an answer (and fix the tags on the question, probably fix the code quoted as well as the problem has nothign to do with jQuery). – T.J. Crowder Feb 10 '18 at 09:04

2 Answers2

1

if you're using .NET as server, for example a ASP.NET MVC Web app. You will need to update on the web.config or in your JsonConfiguration a maximium value allowed by the server to send JSON information to a client.

You can review the solution in this topic: Set an unlimited JSON length

nicobuzzi
  • 56
  • 1
  • thank you, I fixed the problem, I had to change my service: var serializer = new JavaScriptSerializer(); serializer.MaxJsonLength = Int32.MaxValue; – Jawadovic3814 Feb 09 '18 at 21:18
0

thank you, I fixed the problem, I had to change my service: var serializer = new JavaScriptSerializer(); serializer.MaxJsonLength = Int32.MaxValue;

Jawadovic3814
  • 407
  • 1
  • 4
  • 8