2

I am using ASP.net 3.5. A call to a Webmethod using JQuery returns valid JSON data. However when I call the same webmethod to populate a html table using the datatables.net JQuery plugin, I get back the entire html of the page.

**WebMethod:**
 <WebMethod()> _
         Public Shared Function GetData() As String
        Dim a As String = "{""aaData"": [['Trident','Internet Explorer 4.0']]}"
        Return a
    End Function


**Successful JQuery call:**
 $("#Result").click(function() {
    $.ajax({
      type: "POST",
      url: "Default2.aspx/GetData",
      data: "{}",
      contentType: "application/json; charset=utf-8",
      dataType: "json",
      success: function(msg) {
        // Replace the div's content with the page method's return.
        $("#Result").text(msg.d);

      }
    });
  });
});

Unsuccessful JQuery call:

$(document).ready(function() {
    $('#example').dataTable({
        "bProcessing": true,
        "bServerSide": true,
        "sAjaxSource": "Default2.aspx/GetDate",
        "fnServerData": function(sSource, aoData, fnCallback) {
        $.ajax({
        "dataType": 'json',
        "url": sSource,
        "data": aoData,
        "success": fnCallback
        });
        }
    });
});

Any thoughts on why the second call returns html? I tried adding contentType: "application/json; charset=utf-8", to the second ajax call. I get an error.

1
  • Sorry, the "Default2.aspx/GetDate" is a typo. In both the cases, "Default2.aspx/GetData" is being called. The result in the unsuccessful call is still he entire page Commented Dec 17, 2009 at 14:25

1 Answer 1

0

May be you are calling a method which does not exist, so may be an error page is coming in response. Better check what is coming in your response.

"sAjaxSource": "Default2.aspx/GetDate",

In successful call you are using GetData method

url: "Default2.aspx/GetData",

In unsuccessful call you are calling GetDate method.

Sign up to request clarification or add additional context in comments.

1 Comment

Sorry, the "Default2.aspx/GetDate" is a typo. In both the cases, "Default2.aspx/GetData" is being called. The result in the unsuccessful call is still he entire page.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.