weixin_33701294 2018-04-17 17:33 采纳率: 0%
浏览 31

Ajax一次加载数据

Below is my code I used to load some data when click on my divplease advice

$('#data).on('click', function () {

});

function searchData(section) {
    $.ajax({
        type: 'GET',
        dataType: 'json',
        url: '/user/getresults',
        data: {q: section},
        success: function (data) {
            var result = data;
            if (result.success) {

            }
        }
    });
}
  • 写回答

3条回答 默认 最新

  • weixin_33709609 2018-04-17 17:37
    关注

    To avoid multiple calls, add below line to your first click function, but still your code may be executing per clicks where you may need to have overlay on page or some spinner that covers whole page to avoid multiple clicks

    //Prevent form submission
    e.preventDefault();
    e.stopPropagation();
    

    Will be together:

    $('#search').live('click', function (e) {
       searchData(section);
       //Prevent form submission
        e.preventDefault();
        e.stopPropagation();
    });
    
    评论

报告相同问题?