Sharepoint - Failed to load resource: the server responded with a status of 500 (Internal Server Error)

First:
To really troubleshoot the very generic "500 (Internal Server Error)" error, you'd need to get access to the server ULS logs, or attach a debugger to w3wp.exe. 500 only means a basic error has occurred in your code. Could be anything, like a NullReferenceException (e.g. items[i]["Title"] is null), a FileNotFoundException (e.g. list "mysite/Lists/LageData" cannot be found because your Ajax calls a wrong URL), etc...

Second:
Anyway, your approach is probably not the correct one: you're actually loading all the items from the server-side code, and then filter-out the very few you need for the requested page. This is already a performance bottleneck as the C# code sends a SQL request to load all the 5000 items (this leads to SQL overload, network overload, w3wp memory consumption); you're only saving the (gzipped) network load between the SharePoint front server and the client: that's not the most resources-consuming part.

There's 2 possible "better" approches:

  1. Use the version of GetItems() that takes an SPQuery. Add a query that involves an OrderBy clause on ID and filter items starting at a given ID (i.e. the ID of the last item retrieved on the previous page).

    SPQuery query = new SPQuery();
    query.Query = string.Format("<Where><Gt><FieldRef Name='ID' /><Value Type='Counter'>{0}</Value></Gt></Where><OrderBy><FieldRef Name='ID' /></OrderBy>", lastDisplayedItemID);
    query.RowLimit = 15; // Assuming batches of 15 items
    SPListItemCollection items = lista.GetItems();
    

This requires the client to send the last retrieved ID when calling the Web method.

  1. Use SPListItemCollectionPosition.

Based on the chat conversion, we have tried to trace the root cause of 500 internal server error and finally, we found out

  • the OP has used SOAP web service, so it should return XML instead of json as a datatype!

Unfortunately, he tries to return XML before but he faces another issue related to sending parameter where the parameter value always comes null!!!

After checking the code, I found the data: section in the Ajax call had some errors!

Finally, the code should be

 var webserUrl = "/_layouts/15/Load5MoreComments/CommentFetchSvc.asmx";
        var soapRequest =
'<?xml version="1.0" encoding="utf-8"?> \
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" \
xmlns:xsd="http://www.w3.org/2001/XMLSchema" \
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> \
<soap:Body> \
<ReadComments xmlns="http://tempuri.org/">\
<pagenum>4</pagenum>\
</ReadComments>\
</soap:Body> \
</soap:Envelope>';
        $.ajax({
            type: "POST",
            url: webserUrl,
            contentType: "text/xml",
            dataType: "xml",
            data: soapRequest,
            success: function (msg) {
                console.log(msg);
            },
            error: ErrorOccur
        });


        function ErrorOccur(data, status, req) {
            alert(req.responseText + " " + status);
        }

By the way, using SSOM to retrieve list items then try to Load it in lazy load is not a good solution as @Evariste said!

So I suggest using JSOM or REST API to retrieve your items based on specific criteria like showing the list item based on the created date order by Descending and increment the date variable and compare it to the created date in each scroll down event!

Check some examples at

  • How to get filtered sharepoint list item using REST API
  • How to get all items in a view using REST API

Check also

  • Lists and list items REST API reference