3

これは既知のトピックであり、解決策の1つは、呼び出しを同期に変更することです。それでも、それを非同期にして完全な関数でデータを取得する他の方法があるかどうかは私にはわかりませんか?サンプル関数はsuccess関数で新しいアセットオブジェクトを作成し、完全な関数でそれへの参照を取得したいと思います。

        function getPresentation(item) {
        $.ajax({
            type: "GET",
            url: item.Url,
            success: function (data) {
                assets.push(new asset(item.Type, item.Url, data));
            },
            complete: function () {
                /// How to get here the reference for the newly created asset object?
                /// how to alert(asset)?
            },
            error: function (req, status, error) {
                alert('error');
            }
        });

    }
4

1 に答える 1

6

イベントjQXhrで取得したオブジェクトをそのまま使用できます。complete完全なイベントの実際の署名は、次のcomplete(jqXHR, textStatus) ようなものです。

complete:function(jqXHR,status)
{
    if(status == 'success' || status=='notmodified')
    {
        var asset = new asset(item.Type, item.Url, $.parseJSON(jqXHR.responseText))
    }
}
于 2012-04-13T22:49:39.250 に答える