Thursday 18 September 2014

JQuery: Abort the previous inprocess ajax call before calling new request

 $(document).ready(function () {
            var currentRequest = null;
            $('#label').click(function () {
                var text = jQuery(this).val();
                if (currentRequest != null) {
                    currentRequest.abort();
                }
                currentRequest = $.ajax({
                    type: 'POST',
                    data: 'name:xyz',
                    url: 'call.ashx/',
                    success: function (data) {
                        $('#label').html(data);
                    }
                });
            });
        });

No comments:

Post a Comment