0

わかりました、html のチャンクを取得し、それをページの div に投げる ajax jsonp リクエストがあります。問題は、データが読み込まれるときに、コンテンツの種類が適切に配置されることです (div 内に html が構築されるため)。

そのため、最初に一時的なオフページ div にロードし、ロードが完了したら、コンテンツをメイン div に移動します。

    $.getJSON('getsomedata.php?jsoncallback=?',

    function(data) {

    if(data.success=="true")

    {

    // load into temp div


    // pause? until loaded?


    // move content into the real div

    });
4

2 に答える 2

0

コールバック関数を使用して、ajaxリクエストの完了時にdivを表示できます。

$.post('location_of_ajax_file',
    { 'post vals': 'with values'},
    function(data) {
        // this ambiguous function can also just be a callback reference
        // to an external function.
        // It gets called when the ajax request is complete, so you can load 
        // everything into a hidden div, then use this function to show 
        // the div like so:
        $('#hiddendiv').fadeIn(200);

        // fadeIn is cool, but you could also just set the css atribute to show,
        // or switch to another class that includes a show expression.
    }
);

本当にdivを切り替えたい場合は、コールバック関数を使用して、バッファリングdivから画面上のdivにhtmlをコピーすることもできます。

于 2012-06-25T19:30:34.230 に答える
0

私が正しく理解していれば、次のようなものを使用できます

//Will load a message into a temporary div
$('#temp-div').html("Temporary loading message");

//Will replace loading message with the server response
$('#temp-div').html(response);

あなたのコードでは、(html)の効果があるでしょう

<div id="temp-div"> </div>

これは、バックエンドから応答を取得/送信していることも前提としています。繰り返しますが、これは仮定の回答ですが、正しい方向に導くことを願っています。

于 2012-06-25T19:20:17.697 に答える