When clicking on a button, an AJAX request is triggered to send an ID to the controller. The server-side code runs without any errors, but within the controller action there is a section using RestSharp that makes requests to a REST web service. This part of the code is inside a loop and can run multiple times, causing the AJAX request to sometimes take too long and result in an error. What steps should be taken to address this issue?
Here is the AJAX code:
$(document).on("click", "#btn-submit", function () {
$.ajax({
type: 'POST',
url: '/Panel/CheckRefOrderCode',
data: JSON.stringify({
factorrefid: $("#ref-check").val()
}),
contentType: 'application/json; charset=utf-8',
dataType: 'json',
success: function (result) {
if (result.DntSuccess) {
} else {
}
},
error: function () {
}
});
});
The code within the action looks like this:
foreach(string s in str)
{
var client = new RestClient("http://**.com/api/v1/orders/status?support_code=71GD4A");
var request = new RestRequest(Method.POST);
request.AddHeader("token", "15befa43");
IRestResponse response = client.Execute(request);
RefOrderJsonViewModel.RefOrderJson reforderbackJson =
JsonConvert.DeserializeObject<RefOrderJsonViewModel.RefOrderJson>(response.Content);
if (reforderbackJson.status.ToLower() == "ok")
{
performed += reforderbackJson.data.performed;
order_status += reforderbackJson.data.order_status + "^";
}
}
In addition, changes were made to the web.config file:
<httpRuntime executionTimeout="100000000" maxRequestLength="262144" />