weixin_33704234 2017-06-04 21:10 采纳率: 0%
浏览 43

多次执行js脚本

I have a problem with js script.

I load subpage by ajax and append code to div.

$.ajax ({           
    type: "POST",
    url: "load/page/",
    dataType: "json",
    success : function(data) {
        $('.content').empty();
        $('.content').append(data);             
    },
    error : function(e) {
        console.log(e);             
    }           
});

Subpage contains appeal to js script:

<script src="//<?php echo $_SERVER['SERVER_NAME'].'/'.BASE_DIR; ?>/scripts/settings.js"></script>

Why when i execute ajax multiple times settings.js events are executing multiple too? I want to could execute ajax code multiple times but js scripts are executing only once.

  • 写回答

1条回答 默认 最新

  • weixin_33708432 2017-06-04 22:33
    关注

    I replaced $(document) to $('.content') and add line $('.content').off(), now code is working great.

    评论

报告相同问题?