Thursday, September 1, 2011

jQuery $.ajax–Error:Internal Server Error

The javascript code:

    var dataString = "{Id:'" + id+ "',name:'" + name+ "'}";
        type: "POST",
        url: "Default.aspx/SubmitName",
        data: dataString ,
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (message) {
            alert('Thank you!');
        error: function (jqXhr, textStatus, errorThrown) {
            alert("" + textStatus + "; " + errorThrown);

The server side function:

    public static bool SubmitName(string id, string name)
       //some logic here
        return false;

This code would receive an “Internal Server Error” 500 because in the JS the first parameter name is “Id” while on the server side it is “id”. The parameter names have to be the same (including casing!).

No comments:

Post a Comment