Webmethod on my C# (server side) doesn't return data to client side (javascript)

Posted by Philo on Stack Overflow See other posts from Stack Overflow or by Philo
Published on 2014-06-09T21:07:00Z Indexed on 2014/06/09 21:24 UTC
Read the original article Hit count: 263

Filed under:
|
|
|
|

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?

© Stack Overflow or respective owner

Related posts about c#

Related posts about JavaScript