Click here to Skip to main content
15,885,985 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi I'm new to jquery datatables. I am trying to call .aspx page from datatable and return json from webmethod but i'm not able to call aspx page webmethod from js file.

var initTable1 = function () {
        var grid1 = new Datatable();

        grid1.init({
            src: $("#tblScratchOffConfig"),
            dataTable: {
                "responsive": true,
                "deferRender": true,
                "processing": true,
                "ajax": {
                    url: "../WebPages/MyDetails.aspx/GetScratchOff",
                    type: 'GET',
                    dataType: "json"
                },// ajax source                
                "columns": [
                  {},
                  {},
                  {},
                  {},
                  {}
                ],
                "columnDefs": [{ // set default column settings
                    "targets": -1,
                    "data": null,
                    "defaultContent": '<a class="edit" href="">Edit</a>'
                },
                { // set default column settings
                    "targets": -5,
                    "data": null,
                    "visible": false
                }]
            }

        });



<pre lang="c#">
<pre> [System.Web.Services.WebMethod(EnableSession = true)]
        [ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
        public static void GetScratchOffXML()
        {
            try
            {
                HttpContext.Current.Response.Write(json);

            }
            catch (Exception ex)
            {
            }
        }



I prefer .aspx webmethod over .ashx and .asmx for security reasons. Please help me in this.

What I have tried:

Calling .asmx webmethod from .js file but for security reasons i want to use .aspx page
Posted
Comments
Bryian Tan 1-May-17 0:37am    
Any error message? Also, check if the URL is correct.
RAHUL(10217975) 1-May-17 2:41am    
Datatable respond with invalid json and reponse i get is plain Html. Webmethod is not called.
[no name] 3-Aug-17 8:26am    
Check console errors by inspect elements or F12, might be reference or incomplete links that are required there, also share your errors here.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900