jQueryとasp.netでjsonを使用してデータベースからデータを取得し、毎回テーブルごとにこれを行っています。1 つの関数を作成し、すべてのテーブルに (列名、テーブル名、表示するコントロール) などのパラメーターを渡す方法はありますか。
function LoadData(Url, Data, ControlToShow, Columns){
$.ajax({ type: "post",
url: Url,
data: Data,
contentType: "application/json;charset=utf-8", dataType: "json",
success: function (data) {
if (data.d != null || data.d != 'null') {
var items = data.d;
$("#" + ControlToShow).append(items[0].Columns[1]);
}
}
}
または、別の言葉で、次のような列名を渡すことにより、動的な json 配列オブジェクトを使用します
var items = response.d;
var colName = 'Customers';
alert(items[0].colName);
colName = 'CustomerID';
alert(items[0].colName);
または、このようなもの。