asp.net mvc4

Hi Guys,

I have implemented progress bar for my code in order to let users have some indication what is going on behind the screen.

this is my jquery code for progress bar:

 $(document).ajaxStart(function () {
                $("#WaitDialog").dialog('open');
            }).ajaxStop(function () {
                $("#WaitDialog").dialog('close');
            }).ajaxSuccess(function () {
            });


 $("#WaitDialog").dialog({
                draggable: false,
                autoOpen: false,
                resizable: false,
                modal: true
            });

            

Open in new window


The issue:

After I added the progress bar it effected my autocomplete function. when users type the progress bar popup every second. actually when users type to the search box the autocomplete jquery function is going to the controller back and ford.

here is my autocomplete function:

 var performSearch = true;
            $("#searchTxt").autocomplete({
                source: function (request, response) {
                    if (performSearch) {
                        $.ajax({
                            url: '@Url.Action("GetAutocompleteResults", "Purchase")',
                            dataType: "json",
                            data: {
                                searchTxt: $("#searchTxt").val(),
                                option: $("#SearchByOptions").val(),
                                deptid: $("#deptid").val(),
                                catid: $("#catid").val()
                            },
                            success: function (data) {
                                response(data);
                                $("#searchTxt").focus();
                            },
                            error: function (jqXHR, textStatus, errorThrown) {
                                alert(errorThrown);
                                $("#searchTxt").focus();
                            }
                        });
                    }
                },
                minLength: 3,
                delay: 2,
                minChars: 3,
                matchSubset: 1,
                matchContains: 1,
                cacheLength: 10,
                autoFill: true
            }).keydown(function (event) {
                if (event.keyCode == 8) {
                    performSearch = false;
                } else {
                    performSearch = true;
                }
            }).data('autocomplete')._renderItem = function (ul, item) {

                try {
                    var opt = $("#SearchByOptions").val();
                    var txt = '<a><b>ItemLookupCode: </b>' + item.ItemLookupCode +
                        ' <b>Suplier: </b>' + item.SuplierName +
                        ' <b>Department: </b>' + item.DepartmentName +
                        ' <b>Category: </b>' + item.CategoryName + '<br></a>';

                    item.label = txt;

                    if (opt == "1" || opt == "0")
                        item.value = item.ItemLookupCode;
                    else if (opt == "2")
                        item.value = item.Description;
                    else if (opt == "3")
                        item.value = item.SubDescription1;
                    else if (opt == "4")
                        item.value = item.SubDescription2;
                    else if (opt == "5")
                        item.value = item.SuplierName;
                }
                catch (err) {
                    alert(err);

                }
                return $('<li></li>')
                    .data('item.autocomplete', item)
                    .append(item.label)
                    .appendTo(ul);
            };

Open in new window


My question is - how do I disable or stop the progress bar to run when I type in the textbox and query the autocomplete.

Thanks.
LVL 1
Moti Mashiah.NET DeveloperAsked:
Who is Participating?
 
louisfrCommented:
To prevent global events from trigerring, call ajax with the global option set to false:
$.ajax({
    global: false,
    ........
});

Open in new window

0
 
Moti Mashiah.NET DeveloperAuthor Commented:
solved
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.