0

私は非常にうまく機能するjQuery(ブローを参照)でAJAX呼び出しを持っています。すべてのデータを含む成功の新しいテーブルを作成します。ただし、まったく別のページに同じスクリプトを使用し、データを別の方法で表示したいと考えています。何をお勧めしますか?同じajax関数などを使用しながら、プレゼンテーションロジックを削除して別のプレゼンテーションを呼び出すにはどうすればよいですか:

    success: function (data) {
        // Check if we had any campaigns returned.
        if (data.objects.length == 0) {
            // Message to show if user has not created any Campaigns yet.
            bootbox.alert("You don’t have any Campaigns yet.");
        } else {
            // Loop each campaign object and add to the table.
            $.each(data.objects, function () {
                $('#campaign_table').append("<tr><td>" +
                    "<a class='editable editable-click username2' data-title='Enter username' data-placement='right' data-type='text' href='#' data-original-title='' title=''>" +
                    this.name +
                    "</a>" + "</td></tr>");
                console.debug(this.name)
                // this = object in array
                // access attributes: this.Id, this.Name, etc
            });
        }
    }, 
4

1 に答える 1

2

応答の結果を公開する関数を作成します。

function getData() {
    return $.ajax(...);
}

getData().done(function (data) {
    //display the data however you want
});
于 2013-11-04T15:32:06.487 に答える