Search code examples
c#jqueryajaxpostbackwebmethod

Redirect back to Default.aspx


I have a default.aspx (c#) page which has a simple Post AJAX call to a WebMethod that returns a JSON object, so that I can then populate a DataTable. All worked fine until I introduced a login page. Now, when a user is redirected to the Default page, after logging in, the Post never appears in FireBug.

This is my AJAX call:

$.ajax({
            type: 'POST',
            url: '/Default.aspx/GetValueDateSummary',
            contentType: 'json',
            data: {},
            sucess: function (response) {
                renderTable(response.d);
            },
            error: function (errMsg) {
                $('#errorMessage').text(errMsg);
            }
        });
    });

with the code behind being:

[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json, UseHttpGet = true)]
public static List<ValueDateSummary> GetValueDateSummary()
{
    some code in here.....

   return drList;
}

Solution

  • Ok, i sorted it.

    here is the complate Ajax call, seems i was missing the proper contentType and dataType

                   $.ajax({
                   type: 'POST',
                   url: 'Default.aspx/GetValueDateSummary',
                   contentType: 'application/json;charset=utf-8',
                   dataType: 'json',
                   success: function (response) {
                       console.log(response);
                       alert(response.d);
                       renderTable(response.d);
                   },
                   error: function (errMsg) {
                       $('#errorMessage').text(errMsg);
                   }
               });