Home Best way to handle Search in Ajax request
Reply: 0

Best way to handle Search in Ajax request

user1194
1#
user1194 Published in June 20, 2018, 1:32 am

I have search result on keyup event following is my code which if firing on keyup event

  function GetAllThirdParty(pageIndex, Type) {
    $.ajax({
        type: "POST",
        url: "ManageThirdParty.aspx/GetAllThirdParty",
        contentType: "application/json; charset=utf-8",
        data: '{Category: "' + $('#ddlCategoryFilter option:selected').attr('data-category') + '", pageIndex: ' + pageIndex + ', ' +
            'PageSize: ' + $('#ddlRecordsPerPage').val() + ', searchTerm: "' + SearchTerm() + '", Alphabate: "' + $('#hdnAlphabate').val() + '"}',
        beforeSend: function () {
            $('#tblThirdParty').dataTable().fnDestroy();
            $('#tblThirdParty > tbody').empty();
        },
        success: function (data) {
        }
    });
}

When I am typing slower the search result is perfect, but whenever I am typing faster(for same word) search result giving me wrong data because firingup GetAllThirdParty() without completing up current execution.

If I set timeout then search result giving me correct result but it takes lots of time to execute.

How to overcome this situation?

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.305442 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO