jQuery的阿贾克斯::供电进度条? [英] Jquery:: Ajax powered progress bar?

查看:142
本文介绍了jQuery的阿贾克斯::供电进度条?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网页,其中使用jQuery的AJAX功能来发送一些信息。

I have a page which uses jquery's ajax functions to send some messages.

有可能是向上的50K消息发送出去。

There could be upwards of 50k messages to send.

这可能需要一些时间明显。

This can take some time obviously.

我所希望做的是显示出与正在发送的邮件的进度条。

What I am looking to do is show a progress bar with the messages being sent.

后端是PHP。

我怎样才能做到这一点?

How can I do this?


我的解决办法: 发送通过在原来的Ajax调用的唯一标识符。
这个标识符存储在数据库中(或命名具有标识符等文件),随着完成百分比


My solution: Send through a unique identifier in the original ajax call.
This identifier is stored in a database(or a file named with the identifier etc), along with the completion percentage.

这是更新原来的剧本进行。

This is updated as the original script proceeds.

一个函数被调用设置进度(IDENT)

该功能使一个Ajax调用读取的百分比的脚本。
进度条更新 如果返回的百分比不100,
该函数设置超时是1秒后调用自身。

The function makes an ajax call to a script that reads the percentage.
the progressbar is updated If the returned percentage is not 100,
the function sets a timeout that calls itself after 1 second.

推荐答案

您可能必须通过的.html() GIF动画加载到结果区域,直到你的AJAX功能返回回结果。只是一个想法。

You could have an animated gif load via .html() into the results area until your ajax function returns back the results. Just an idea.

关于jQuery UI的进度条,间歇性地通过你的脚本,你会想要重新呼应$ P $数值psenting完成百分比作为指定的javascript变量。例如...

Regarding the jquery ui progress bar, intermittently through your script you'll want to echo a numeric value representing the percent complete as an assigned javascript variable. For example...

// text example php script
if (isset($_GET['twentyfive-percent'])) {
    sleep(2); // I used sleep() to simulate processing
    echo '$("#progressbar").progressbar({ value: 25 });';
    }
if (isset($_GET['fifty-percent'])) {
    sleep(2);
    echo '$("#progressbar").progressbar({ value: 50 });';
    }
if (isset($_GET['seventyfive-percent'])) {
    sleep(2);
    echo '$("#progressbar").progressbar({ value: 75 });';
    }
if (isset($_GET['onehundred-percent'])) {
    sleep(2);
    echo '$("#progressbar").progressbar({ value: 100 });';
    }

和下面是我用来获取进度条,以更新其位置的功能。小坚果,我知道了。

And below is the function I used to get the progress bar to update its position. A little nuts, I know.

avail_elem = 0;
function progress_bar() {
    progress_status = $('#progressbar').progressbar('value');
    progress_status_avail = ['twentyfive-percent', 'fifty-percent', 'seventyfive-percent', 'onehundred-percent'];
    if (progress_status != '100') {
        $.ajax({
            url: 'test.php?' + progress_status_avail[avail_elem],
            success: function(msg) {
                eval(msg);
                avail_elem++;
                progress_bar();
                }
            });
        }
    }

如果我猜的话,我敢打赌,有一个更好的办法......但是,这是它为我工作,当我测试的方式。

If I had to guess, I bet there is a better way... But this is the way it worked for me when I tested it.

这篇关于jQuery的阿贾克斯::供电进度条?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆