The problem I am facing is that the webClient.UploadData method is firing twice instantly from ajax request. But the same webClient.UploadData method is firing only once when invoked from aspx page. From the logs I can see the time of both the requests sent is exactly the same.. 2016-06-23 05:54:48.477
Below is the code snippet -
var DTO = JSON.stringify({Date: date, Month: month, AgeRange: ageRange, MethodName: "Enroll" });
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "/mypath/TasksHandler.ashx",
data: DTO,
async: true,
success: function(result) {
......
}
TasksHander will call the below method -
using (var client = new WebClient())
{
client.Headers[HttpRequestHeader.ContentType] = "application/json";
client.Headers[HttpRequestHeader.Accept] = "application/json";
var data = Encoding.UTF8.GetBytes(dataInput);
byte[] result = client.UploadData(url, "POST", data);
output = Encoding.UTF8.GetString(result, 0, result.Length);
}
My speculation is this could be due to setting of async property to true in ajax call? Please let know if any thoughts on this.
The problem in the code was there were 2 places which were having a CSS class "dob" in HTML and there was jquery code with $(".dob").each(function(elem,val){...} This function was leading to making ajax call...