Home > database >  Ajax and error cannot read properties of undefined
Ajax and error cannot read properties of undefined

Time:07-15

So I am trying to get some data from a table using ajax but this error keeps popping up and I know its related to parameters but I have none of the parameters it says are wrong anyone got any ideas?

I am working in asp.net 6 and am trying to get the data to a controller.

I am currently working in C# and ajax

(function () {
    "use strict"

    window.onload = function () {
        //Reference the DropDownList.
        var ddlYears = document.getElementById("ddlYears");

        //Determine the Current Year.
        var currentYear = (new Date()).getFullYear()   10;
        var less = (new Date()).getFullYear() - 10;
        //Loop and add the Year values to DropDownList.

        for (var i = less; i <= currentYear; i  ) {
            var option = document.createElement("OPTION");
            option.innerHTML = i;
            option.value = i;
            ddlYears.appendChild(option);
        }


    };
    var ScopeTable;

    $(document).ready(function () {
        ScopeTable = $("#tblScopeView").DataTable({
            dom: "Bfrtip",
            paging: true,
            pagingType: "full_numbers",
            buttons: [
                "csvHtml5"
            ],
            columns: [
                { data: 'WBS' },
                { data: 'Title' },
                { data: 'Rev' },
                { data: 'ScopeStatus' },
                { data: 'BCP' },
                { data: 'BCPApprovalDate' },
                { data: 'Manager' },
                { data: 'ProjectControlManager' },
                { data: 'ProjectControlEngineer' },
                {
                    mRender: function (data, type, row) {
                        return "<i class='fa fa-edit btnAddEditScope'></i><span>&nbsp; Edit</span >"
                    },
                    class: "btnAddEditScope table-button",
                    orderable: false
                },
                {
                    mRender: function (data, type, row) {
                        return "<i class='fa fa-trash btnDeleteRow'></i><span>&nbsp; Delete</span >"
                    },
                    orderable: false,
                    class: "table-button"

                }



            ],
            createdRow: function (row, data, index) {
                $(row).attr("data-id", data.WBSNumber);
                $(row).attr("data-month", data.FiscalMonth);
                $(row).attr("data-year", data.FiscalYear);
            }

        });
        $(document).on("click", ".btnAddEditScope", btnAddEditScope_click);
        $("#spnrSave").hide();

    });
    function btnAddEditScope_click() {
        console.log("button clicked")

        $.ajax({
            url: "Scope/AddEditScope",
            type: "GET",
            success: function () {
                $("#vw_AddEditScope").modal("show");
            }
        });

    }


}());

Error that is being posted

CodePudding user response:

Figured it out just had do adjust my ajax and it worked fine. The tutorial I found is here https://datatables.net/examples/api/multi_filter.html

var ScopeTable;
    $(document).ready(function (e) {
        ScopeTable = $("#tblScopeView").DataTable({
            dom: "Bfrtip",
            paging: true,
            pagingType: "full_numbers",
            buttons: [
                "csvHtml5"
            ],

            columns: [
                { data: 'WBS' },
                { data: 'Title' },
                { data: 'Rev' },
                { data: 'ScopeStatus' },
                { data: 'BCP' },
                { data: 'BCPApprovalDate' },
                { data: 'Manager' },
                { data: 'ProjectControlManager' },
                { data: 'ProjectControlEngineer' },
                {
                    mRender: function (data, type, row) {
                        return "<i class='fa fa-edit btnAddEditScope'></i><span>&nbsp; Edit</span >"
                    },
                    class: "btnAddEditScope table-button",
                    orderable: false
                },
                {
                    mRender: function (data, type, row) {
                        return "<i class='fa fa-trash btnDeleteRow'></i><span>&nbsp; Delete</span >"
                    },
                    orderable: false,
                    class: "table-button"

                },
            ],           
            createdRow: function (row, data, index) {
                $(row).attr("data-id", data.WBSNumber);
                $(row).attr("data-month", data.FiscalMonth);
                $(row).attr("data-year", data.FiscalYear);

            },
            error: function (e) {
                console.log(e);
            }
        });


        $('#tblScopeView tfoot th').each(function () {
            var title = $("#tblScopeView").eq($(this).index()).text();
            $(this).html('<input type="text"  placeholder="Search '   title   '" />');

            ScopeTable.columns().every(function () {
                var dataTableColumn = this;
                $(this.footer()).find('input').on('keyup change', function () {
                    dataTableColumn.search(this.value).draw();
                });
            });
        });

        $("#spnrSave").hide();
        $(document).on("click", ".btnAddEditScope", btnAddEditScope_click);
    });
  • Related