Ajax call .net web service

Ajax call .net web service

deadmaskdeadmask Posts: 3Questions: 0Answers: 0
edited November 2014 in Free community support

Hi,
i used a Server-Side processing to load a data. When I call my .net Web Service, return this error :

DataTable warning : table id=example -Ajax error. For more information about this error, please see http://datatables.net/tn/7

But I don't understand this error.

This is my code

        $('#example').dataTable( {
           "processing": true,
           "serverSide": true,
           "ajax": "WebService.asmx/GetData"
        } ); 

Can you help me?

Thanks

Replies

  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395

    But I don't understand this error.

    It's explained in the link: http://datatables.net/tn/7

    You should follow the explanation to find out what status code was returned by the ajax request.

  • deadmaskdeadmask Posts: 3Questions: 0Answers: 0
    edited November 2014

    500 Internal Error is the error.

    Error description :

                    Request format not recognized. URL ends unexpectedly with '/ GetData'
    

    If I call the WebMethod with Jquery ajax i have a positive return.
    Code :

            $.ajax({
               type: "POST",
               url: "WebService/GetData",
               cache: false,
               contentType: "application/json; charset=utf-8",
               data: "{}",
               dataType: "json",
               success: function (data) {
                 alert(data.d);
               }
            });
    

    I also decorated my WebService with <System.Web.Script.Services.ScriptService()>.

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin

    Sounds like there might be a routing problem, or if you need to add the contentType header,t hen you can use ajax as an object and pass the option in.

    Allan

  • deadmaskdeadmask Posts: 3Questions: 0Answers: 0
    edited November 2014

    I solved this problem. The error was due to the configuration of the call to the WebMethod.
    This is the correct code :

             $('#example').dataTable({
                "processing": true,
                "serverSide": true,
                "ajax": {
                    type: "POST",
                    url: "WebService/GetData",
                    contentType: "application/json; charset=utf-8",
                    data: "{}",
                    dataType: "json"
                }
            });
    

    Now, I have a new error : -.-

             Sys.ParameterCountException: Mismatch in the number of parameters
    

    I followed this guide : http://datatables.net/manual/server-side, for set the input parameters.

    This is the first definition of the method that i used:

             Public Function GetData(draw As Integer, start As Integer, length As Integer, searchValue() As String, searchRegex() As String, order() As Object, columns() As Object) As String 
    

    This is the second:

                Public Function GetData(draw As Integer, start As Integer, length As Integer, searchValue() As String, searchRegex() As String, orderColumn() As Integer, orderDir() As String, columnsData() As String, columnsName() As String, columnsSearchable() As Boolean, columnsOrderable() As Boolean, columnsSearchValue() As String, columnsSearchregex() As String) As String
    

    And this is the last :

             Public Function GetData(draw As Integer, start As Integer, length As Integer, searchValue As String, searchRegex As String, orderColumn As Integer, orderDir As String, columnsData As String, columnsName As String, columnsSearchable As Boolean, columnsOrderable As Boolean, columnsSearchValue As String, columnsSearchregex As String) As String
    

    Can you help (again) me?

    Thanks

This discussion has been closed.