下面是2个jquery函数。当我调用getData()函数时,我想重新加载页面,然后调用play_audio()函数。但这是行不通的。有人可以帮我吗?
function getData(id){
if(id){
location.reload();
play_audio(id);
}
}
function play_audio(id) {
$('.load-container').show();
var action_url = HTTP_ROOT + "/site/getaudiofile/";
$.ajax({
url: action_url,
data: {"audio_id": id},
method: "post",
async: false,
success: function (res) {
AP.destroy();
res = JSON.parse(res);
var resdata = new Array();
resdata = res.data;
var action = 'add';
var index = 0;
var title = resdata[index].title;
muviAudioMusicPlayerObj = [];
updateQueueList(resdata,action,index);
$('.art-desc h6').html(title);
$('.load-container').hide();
}
});
}
答案 0 :(得分:4)
尝试在重新加载之前将哈希添加到您的网址中,然后查找哈希:
function getData(id){
if (id) {
location.hash = 'playaudio-' + id;
location.reload();
}
}
$( document ).ready(function() {
if (location.hash.indexOf('#playaudio') !== -1) {
var splitHash = location.hash.split('-');
var id = splitHash[1];
play_audio(id);
}
});