Webmethod on my C# (server side) doesn't return data to client side (javascript)
- by Philo
I am using a c# Webmethod to return results to my client side written in Javascript.
[WebMethod]
public static string MyMethod(string Id)
{
SQL QUERIES and then ....
// adding data to member class.
Member member = new Member(Name, DOB, Sex, Member_Identification, Dates_of_services);
return JsonConvert.SerializeObject(member); <-- member is a class of List strings
}
And on the client side you could invoke this method using the jQuery.ajax() function like this:
$.ajax({
url: 'default.aspx/MyMethod',
type: 'POST',
contentType: 'application/json; charset=utf-8',
data: JSON.stringify({ ID : ID }),
success: on success {
}
});
function onSuccess(data) {
// parses json returned data
var jsondata = $.parseJSON(data.d);
..... }
Now the data returned to the client side are Lists of Strings. This method works for me most times. However for one or two queries, the method runs forever without returning to the client side.
On the server side however, I can use breakpoints and see that all the Lists of strings have been formed correctly. But I cannot seem to find out why they are never returned to the client side. My code reaches till the return statement on the server side and then the program just runs forever. It never reaches the function 'onsuccess'
Can anyone tell me why this can happen? Anomalies in data maybe?