杀死所有正在进行的XHR请求

kill all ongoing XHR requests

$('#search-box').keyup(function() { // bind the search data var input = $('.search-input').val();

 $.getJSON({ // get JSON data
        url: 'example/query.php?keyword=' + input,
        //pre-load
        beforeSend: function() {
            $(".search-lists").html("<span class='loading'><img src='_/images/loading.gif' /></span>");
        },
        success: function(data) { 
            if (input.length >= 3) { // limit keyword to >=3
                var output = "<ul class='search-lists'>"; //output search data list
                $.each(data, function(key, val) {
                    output += '<li>';
                    output += '<a>' + val.term + '</a>';
                    output += '</li>';

                });
                output += '</ul>';
                $('.search-results').html(output);
                console.log('load ajax');
            } // end if

           else {
                console.log('kill ajax');
           }
        }


    }); // JSON request

}); // data bind
查看全部
weixin_33712987
weixin_33712987
2016/04/29 06:23
  • ajax
  • javascript
  • 点赞
  • 收藏
  • 回答
    私信

3个回复