Ajax call asp.net api for to long

Ajax call asp.net api for to long

s.jhun03s.jhun03 Posts: 2Questions: 1Answers: 0
edited August 2020 in Free community support

Link to test case:
First call on the api on the back end using datatable is okay
When trying to Call again the api for the second time it takes to long passing in the api
and third, fourth and etc is okay no problem
Debugger code (debug.datatables.net):
Front end

 table = $('#tblServiceNumbersContent').DataTable({
            "responsive": true,
            "dom": '<"top"pl>rt<"bottom"fi><"clear">',
            "searching": false,
            "ordering": false,
            "bInfo": false,
            "lengthChange": false,
            "pageLength": 1000,
            language: {
                processing: '<i class="fa fa-spinner fa-spin fa-2x fa-fw"></i>',
                paginate: {
                    next: '>', // or '→'
                    previous: '<' // or '←' 
                }
            },
            "columnDefs": [
                //Added classes in Dom
                { "className": "service-number-charges", "targets": [2] },
                { "className": "service-number", "targets": [1] },
            ],
            "processing": true,
            "serverSide": true,
            "async": true,
            //"deferLoading": 1000,
            //"scrollX": true,
            "deferRender": true,
            //searchDelay: 1500,
            "ajax":
            {
                "url": "expensemanagement.aspx/GetServiceNumbersFromTicketDetailsDataTable",
                "contentType": "application/json",
                "type": "POST",
                "dataType": "JSON",
                "data": function (d) {
                    //setting up Paramaters for APi 
                    //run_waitMe('facebook', 'tblServiceNumbersContentBody', 'Loading...');
                    console.log("sent")
                    var param = JSON.stringify({
                        ticketId: ticketId,
                        draw: d.draw,
                        offsetRow: d.start,
                        fetchRow: d.length,
                        searchCriteria: $('#serviceNumberContentFilter').val(),
                        IsShowMissingSN: DataService.IsShowMissingSn
                    });
                    return param;
                },
                "dataSrc": function (json) {
                    //Receive from the APi 
                    console.log("response");
                    DataService.SavedServiceNumbersTicketDetails = json.d.serviceNumberResult;
                    json.draw = json.d.draw;
                    json.recordsTotal = json.d.recordsTotal;
                    json.recordsFiltered = json.d.recordsFiltered;
                    json.data = json.d.data;         

                    if (json.data.length > 0) {


                        $('#import').hide();
                        $('#importXml').hide();
                        $('#genericImport').hide();
                        $('#append').removeClass('hidden');

                        //for (var i = 0; i < json.d.data.length; i++) {
                        //    commonService.toCurrency(json.d.data[i].ChargeAmount);
                        //}
                        commonService.toCurrency(json.d.TotalChargeAmount); 
                        
                    } else {
                       // $('#tblServiceNumbersContent_processing').removeClass('dataTables_processing');
                        $('#expense-management-window').waitMe('hide');
                        $('#tblServiceNumbersContentBody').waitMe('hide');

                        return [];
                    }

                    $('#expense-management-window').waitMe('hide');
                    $('#tblServiceNumbersContentBody').waitMe('hide');

                    //loadHideColumns(table);
                    totalChargeAmount = parseFloat(json.d.TotalChargeAmount);

                    var return_data = json;
                    return return_data.data;
                },
                "beforeSend": function () {
                    console.log("before")
                    // Here, manually add the loading message.
                    $('#tblServiceNumbersContent > tbody').html(
                        '<tr class="odd">' +
                        '<td valign="top" colspan="6" class="dataTables_empty">Loading&hellip;</td>' +
                        '</tr>'
                    );
                }
            },
            "columns": [
                { "data": "Multiple" },
                { "data": "ServiceNumber" },
                { "data": "ChargeAmount" },
                { "data": "ActionDisplay" }
            ],
            "action": function (e, dt, node, config) {
                var data = oTable.rows({ selected: true }).data();
                console.log("data---" + data);
            },
            "fnDrawCallback": function () {
                //After Display
                $('#tblServiceNumbersContent').css('width', '');
                //Hide Column 1
                $("#tblServiceNumbersContent tbody tr td:nth-child(1)").css("display", "none");
                $("#tblServiceNumbersContent thead tr th:nth-child(1)").css("display", "none");
                displayServiceNumbersFooter();
                $.fn.DataTable.ext.pager.numbers_length = 6;

                var pageLenght = this.fnPagingInfo().iTotal;

                // if the list is more than 1001 
                if (pageLenght < 1001) {
                    $('.dataTables_paginate').hide();
                    document.getElementById("service-number-content").style.position = null;
                    document.getElementById("service-number-content").style.top = null;
                } else {
                    $('.dataTables_paginate').show();
                    document.getElementById("service-number-content").style.position = "relative";
                    document.getElementById("service-number-content").style.top = "-40px";
                }

                $('#serviceNumberTotal').html(commonService.toCurrency(totalChargeAmount));

                table.settings()[0].jqXHR.abort();

            },
            "createdRow": function (row, data, dataIndex) {

                //Creating row individual
                if (data.InventoryId != 0) {
                    if (data.Status) {
                        $(row).addClass('row-inactive');
                    } else {
                        // <tr>
                    }             
                } else {
                    $(row).addClass('row-invalid');
                }

                $(row).find('td:nth-child(4)').addClass('text-center');
            }
        });

**Back end**

  [WebMethod]
        public static object GetServiceNumbersFromTicketDetailsDataTable(int ticketId, int draw, int offsetRow = 0, int fetchRow = 50, string searchCriteria = "",bool IsShowMissingSN = false)
        {
            var repo = new ServiceNumbersRepo();
            var serviceNumberDataTableReqDTO = new ServiceNumberDataTableReqDTO();
            var count = 0;

            var result = repo.GetServiceNumbersFromTicketDetailsDataTable(ticketId, draw, offsetRow, fetchRow, searchCriteria, IsShowMissingSN);

            //if (IsShowMissingSN)
            //{
            //    result = result.Where(x => x.InventoryId == 0 || x.InventoryId == null).ToList();
            //}

            var totalAmount = repo.GetServiceNumbersFromTicketDetails_TotalChargeAmount(ticketId);
            serviceNumberDataTableReqDTO.draw = draw;
            serviceNumberDataTableReqDTO.data = FilteredServiceNumbersTicketDetails(result);
            serviceNumberDataTableReqDTO.serviceNumberResult = result;
            serviceNumberDataTableReqDTO.TotalChargeAmount = totalAmount;

            if (string.IsNullOrWhiteSpace(searchCriteria))
            {
                count = repo.GetServiceNumbersFromTicketDetailsCount(ticketId, IsShowMissingSN);
                serviceNumberDataTableReqDTO.recordsFiltered = count;
                serviceNumberDataTableReqDTO.recordsTotal = count;
            }
            else
            {
                var withoutOffSetCount = repo.GetServiceNumbersFromTicketDetailsCountWithoutOffset(ticketId, searchCriteria, IsShowMissingSN);

                serviceNumberDataTableReqDTO.recordsFiltered = withoutOffSetCount;
                serviceNumberDataTableReqDTO.recordsTotal = withoutOffSetCount;
            }

            return serviceNumberDataTableReqDTO;


        }

Error messages shown:
No error but takes to long to call on the api
Description of problem:
Having a problem calling for the second time on the api using datatable

Edited by Colin - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

Answers

  • colincolin Posts: 15,237Questions: 1Answers: 2,599

    When trying to Call again the api for the second time it takes to long passing in the api and third, fourth and etc is okay no problem

    That's odd, I can't think why that would be the case. Can you link to your page so we can take a look, please?

    Colin

  • s.jhun03s.jhun03 Posts: 2Questions: 1Answers: 0

    Hi colin

    The link to our page is private but i can send a video clip and the code ?

    Jhun

  • colincolin Posts: 15,237Questions: 1Answers: 2,599

    A video wouldn't help, they're hard to debug ;) Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

This discussion has been closed.