jquery .map函数执行两次

时间:2018-04-17 10:02:07

标签: jquery

我使用此函数动态地将html加载到页面中。

我调用该函数一次,但它运行了两次。 (我知道它因为console.log中的消息而运行了两次)。

任何想法为什么它执行两次以及如何阻止它?

function GetAjaxHTML() {
    $.map($(".AjaxContent"), function(el, i) {
        return $.ajax({ 
            url: '/ajax/' + $(el).prop("id").split("_")[0] + '/' + $(el).prop("id").split("_")[1],
            success: function(response) { 
                $(el).html(response); 
                console.log($(el).prop("id").split("_")[1] + ' loaded');
            }
        });
    }); 
}

此致 丹

0 个答案:

没有答案