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 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:
ajax(url,mainFunction,true) function ajax(url, callback, async) { var date = new Date(); var ticks = date.getTime(); if (url.indexOf('?') == -1) url = url + "?tick=" + ticks; else url = url + "&tick=" + ticks; $.ajax({ type: 'GET', url: url, dataType: 'html', async: async == undefined ? true : async, success: function (data) { if (data != undefined) callback(data); }, error: function (xhr, textStatus, errorThrown) { //throw error }, complete: function () { } }); }
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报