2015-06-23 07:58 阅读 34


Written a Jquery function in main file (index.php) & want to call same function in ajax file that is called from main file.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

1条回答 默认 最新

  • 已采纳
    duanjiong5686 duanjiong5686 2015-06-23 08:08

    if the function in the main page and you inject ajax to container inside it, the function need to be available for calling, in the end of the ajax file add function() //main function

    you can also choose another approach after the ajax success you can call the function directly... by passing it as callback for example:

    function ajax(url, callback, async) {
        var date = new Date();
        var ticks = date.getTime();
        if (url.indexOf('?') == -1)
            url = url + "?tick=" + ticks;
            url = url + "&tick=" + ticks;
            type: 'GET',
            url: url,
            dataType: 'html',
            async: async == undefined ? true : async,
            success: function (data) {
                if (data != undefined)
            error: function (xhr, textStatus, errorThrown) {
               //throw error
            complete: function () {
    点赞 评论 复制链接分享