dongpo0409 2011-10-11 19:25
浏览 67

使用XHR的进度事件来监视PHP / MySQL查询

I have made a progress bar to show how much 'progress' an XHR request has made, but it only seems to work with the testing method I used which got a URL's content then JSON encoded it - this was a 'GET' method.

function get_album_percent(token) {
var loadingDlg = document.getElementById('loadingDlg'),
    loadingDlg_title = document.getElementById('loadingDlg_title'),
    loadingDlg_bar = document.getElementById('loadingDlg_bar'),
    xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
    console.log(xhr.readyState);
    if (xhr.readyState == 1) {
        if (!loadingDlg.classList.contains('open')) {
            loadingDlg.classList.add('open');
            loadingDlg.classList.remove('close');
        } else {
            loadingDlg.classList.add('close');
            loadingDlg.classList.remove('open');
        }
        loadingDlg_title.innerHTML = 'Getting Facebook albums...';
    }
    if (xhr.readyState == 3) {
        console.log('3', xhr);
        xhr.onprogress = function(event) {
            console.log('onloadstart, response', event);
            var percent = Math.round((event.loaded/event.total) * 100) + '%';
            loadingDlg_bar.style.width = percent;
        }
    }
}
xhr.open('POST', 'http://mydomain.co.uk/api/facebook/get/userinfo.php?token=' + token);
xhr.send(null);
}

However when I use the method I wanted to originally use - which got a Facebook users albums, photos and tags from a URL paramter then inserted them into 3 tables using PHP/MySQL - all that happens is that readystate 1 is fired, then 2, 3 and 4 is fired at the end, after the xhr has happened.

Is there a reason for this? Are there any solutions?

Thanks, Adam C.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 python的qt5界面
    • ¥15 无线电能传输系统MATLAB仿真问题
    • ¥50 如何用脚本实现输入法的热键设置
    • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
    • ¥30 深度学习,前后端连接
    • ¥15 孟德尔随机化结果不一致
    • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
    • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
    • ¥15 谁有desed数据集呀
    • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100