Quantcast
Channel: Recent Discussions — DataTables forums
Viewing all articles
Browse latest Browse all 82823

ServerSide Ajax Call not working with Non-MVC asp.net project.

$
0
0

I've tried alot to search on google but not getting anything related to Serverside ajax with Non-MVC asp.net.
I've asked on stackoverflow also. stackoverflow.com/questions/43227910/jquery-datatables-serverside-ajax-with-asp-net-webmethod

PageLibrary.aspx :

<body>
    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
    <link href="https://cdn.datatables.net/1.10.13/css/jquery.dataTables.min.css" rel="stylesheet" />
    <script type="text/javascript" src="https://cdn.datatables.net/1.10.13/js/jquery.dataTables.min.js"></script>
        <script>
            try {
                $(document).ready(function () {
                    $('#GridBooksList').dataTable({
                                "bServerSide": true,
                                "bProcessing": true,
                                "sAjaxSource": "PageLibrary.aspx/GetBooks",
                                "aoColumns": [
                                               { "sName": "NAME" },
                                               { "sName": "SERIAL_NUMBER" },
                                               { "sName": "AUTHOR" }
                                ]
                            });
                });
            } catch (ee) {
                alert(ee.message);
            }
    </script>
    <form id="form2" runat="server">
        <table id="GridBooksList" class="table table-bordered" style="text-align: center; width: 100%; height:100%" >
            <thead>
                <tr>
                <th>NAME</th>
                <th>SERIAL_NUMBER</th>
                <th>AUTHOR</th>
            </tr>
            </thead>
            <tbody>
            </tbody>
        </table>
    </form>
</body>

PageLibrary.aspx.cs :

    public static IList<BookDetail> booklist = null;
    
    [WebMethod]
    public static IList<BookDetail> GetBooks(JQueryDataTableParamModel param)
    {
        try
        {
            int i = 0;
            while (i < 10)
            {
                booklist.Add(new BookDetail { AUTHOR = "AAAA" + i.ToString(), NAME = "BBB" + i.ToString(), SERIAL_NUMBER = "CCC" + i.ToString() });
                i++;
            }
            return booklist;
        }
        catch
        {
            return null;
        }
    }

Getting error :
DataTables warning: table id=GridBooksList - Invalid JSON response. For more information about this error, please see http://datatables.net/tn/1

Please tell me where i'm doing wrong? How can i implement Serverside ajax call in non-mvc asp.net project.

Regards,
Jack


Viewing all articles
Browse latest Browse all 82823

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>