8

大きなjsonリストを取得するajax呼び出しがあります。json ロードの実際の値を取得するプログレス バーを作成する方法はありますか (たとえば、200 のうち 1 がロードされていることを示すステータス バー)。

今、私はかなり基本的な Ajax 呼び出しを持っています

function SendAjax(urlMethod, jsonData, returnFunction) {
    $.ajax({
        type: "GET",
        contentType: "application/json; charset=utf-8",
        url: urlMethod,
        data: jsonData,
        dataType: "json",
        success: function (msg) {
            if (msg != null) {
                ReturnJson(msg);
            }
        },
        error: function (xhr, status, error) {
            // Boil the ASP.NET AJAX error down to JSON.

            var err = eval("(" + xhr.responseText + ")");

            // Display the specific error raised by the server
            alert(err.Message);
        }
    });
}
4

3 に答える 3

2

アプリケーションのグローバル スコープでAjaxStartを使用してみてください。つまり、コードをレイアウト ファイルに入れることができ、処理が長い場合は進行状況インジケーターが表示されます...

$(document).ajaxStart(function() {
   $( "#loading" ).show();
 });

パーセンテージ - javascript/jquery を使用して、プリロード時に例と回答を確認できます。

于 2013-05-21T05:01:55.030 に答える
0

サーバー側のコードにアプリケーションの状態を共有する方法 (PHP の $_SESSION など) がある場合、データを要求する要求と最初の要求の進行状況を確認する要求の 2 つの別個の要求を行うことができます。最初のリクエストが完了するまでタイマーで 2 番目のリクエストを繰り返し、各アイテムが処理されるたびに $_SESSION (またはサーバー コードで機能するもの) を更新します。

例: 最初のページは、後続の AJAX 呼び出しが Cookie を持ち、共有データにアクセスできるように、セッションを開始する必要があります。

<?php
session_start();
session_write_close(); // close the session so other scripts can access the file (doesn't end the session)
// your page content here
?>

処理を開始するための最初の AJAX 呼び出し:

<?php
function updateSession($count){
    session_start(); // open the session file
    $_SESSION['progress'] = $count;
    session_write_close(); // let other requests access the session
}
// as you process each item, call the above function, ex:
for ($i = 1; $i <= 10; $i++) {
    updateSession($i);
}
?>

2 番目の AJAX 呼び出し (X 秒ごとに繰り返される) は次のようになります。

<?php
session_start(); // open the session file
echo @$_SESSION['progress'] or 0; // echo contents or 0 if not defined
session_write_close(); // let other requests access the session
?>

申し訳ありませんが、ASP.NET についてはわかりませんが、上記のコードがお役に立てば幸いです。

于 2013-10-04T00:01:47.083 に答える