Answered by:
How to load 2000+ Records using Ajax Webmethod

Question
-
User-2062901272 posted
Hi experts,
I have a problem in loading a thousand records using ajax it gives me an error "internal Error 500". it can only handled less than 500 records
How can i overcome this problem. Please see my code below thanks in advance.
Webmethod in code Behind
<WebMethod()> _ Public Shared Function BindDataCountryState(ByVal LocationCode As String) As List(Of ListItem) Dim con As New SqlConnection(ConfigurationManager.ConnectionStrings("MyConnectionString").ConnectionString) Dim CountryState As New List(Of ListItem)() Try Using con Using cmd As New SqlCommand("usp_GetCountryState") cmd.CommandType = CommandType.StoredProcedure cmd.Parameters.AddWithValue("@LocationCode", LocationCode) cmd.Connection = con con.Open() Using sdr As SqlDataReader = cmd.ExecuteReader() While sdr.Read() CountryState.Add(New ListItem() With { _ .Value = sdr("Code").ToString(), _ .Text = sdr("Description").ToString() _ }) End While End Using Return CountryState End Using End Using Catch ex As Exception HttpContext.Current.Session("error_message") = ex.Message &" Return CountryState Finally If con IsNot Nothing Then con.Close() con.Dispose() End If End Try End Function
Asp.net Code
var f = document.getElementById("<%=DropDownListPetitionerCountry.ClientID%>");
f.onchange();
var LocationCode = $(f).val();
var parameter = { LocationCode: LocationCode }; $.ajax({ type: "POST", contentType: "application/json; charset=utf-8", url: "Default.aspx/BindDataCountryState", data: JSON.stringify(parameter), dataType: "json", ////data: '{}', success: function (f) { var ddlCustomers = $("[id*=DropDownListStateProvince]"); $.each(f.d, function () { ddlCustomers.append($("<option></option>").val(this['Value']).html(this['Text'])); }); }, error: function (result) { alert("Error " + result.status); console.log(result.status) } });Monday, October 2, 2017 3:59 AM
Answers
-
User-335504541 posted
Hi ryoka012,
JSON has a maximum length. Please try to add following code In web.config:
<appSettings> <add key="aspnet:MaxJsonDeserializerMembers" value="150000" /> </appSettings>
Best Regards,
Billy
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Friday, October 6, 2017 8:05 AM
All replies
-
User2119946224 posted
Hi,
Looks like in your web.config file you have to increase HTTP transfer limit. Please take a look below link. It will resolve your issue.
https://msdn.microsoft.com/en-in/library/aa528822.aspx
https://www.codeproject.com/Articles/10842/Setting-up-Web-config-to-allow-uploading-of-large
Please let me know if it does not work for you.
Regards,
Hasmukh
Monday, October 2, 2017 6:42 AM -
User-2062901272 posted
Hi hkholakiya,
Thanks for the reply.
How ever it seems it does not solved my problem after configuring the settings.
Monday, October 2, 2017 7:13 AM -
User475983607 posted
Hi hkholakiya,
Thanks for the reply.
How ever it seems it does not solved my problem after configuring the settings.
A 500 errors using AJAX often means there is something wrong with the request. Have you tried using developer tools to verify the LocationCode property value is populated and the value is expected? Have you tried using the Visual Studio debugger to verify the web method is getting invoked? Have you tried invoking the stored procedure from SSMS?
Monday, October 2, 2017 3:04 PM -
User-2062901272 posted
Hi mgebhard,
Thanks for the reply.
Have already tried that, i tried to limit my rows to just 400 and it is working fine, and no errors encountered.
Tuesday, October 3, 2017 4:37 AM -
User-335504541 posted
Hi ryoka012,
JSON has a maximum length. Please try to add following code In web.config:
<appSettings> <add key="aspnet:MaxJsonDeserializerMembers" value="150000" /> </appSettings>
Best Regards,
Billy
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Friday, October 6, 2017 8:05 AM -
User-2062901272 posted
Hi Billy,
Thanks for your reply.
It works like magic.
Thanks again..
Friday, October 6, 2017 8:54 AM