接口请求返回变量处理方式

来源:互联网 发布:安卓程序员考试 编辑:程序博客网 时间:2024/06/04 23:33
function requestPlayCount(albumId) {
    var head = document.getElementsByTagName('head')[0];
    var script = document.createElement('script');
    script.src = 'http://cache.video.qiyi.com/p/' + albumId + '/';

    script.type = 'text/javascript';

   //IE浏览器

    if(jQuery.browser.msie) {
        script.onreadystatechange = function(){
            if(this.readyState == 'loaded' || this.readyState == 'complete'){
                cj_callback(eval('playCount_' + albumId)); //'playCount_' + albumId返回的变量的名字,这里使用eval()函数将字符串转为了变量
            }
        }
    } else {
        script.onload = function(){
            cj_callback(eval('playCount_' + albumId));
        }
    }
    head.appendChild(script);
}
function cj_callback(t) {
    
}
原创粉丝点击