そのため、リスト内のものをドラッグ アンド ドロップして順序を変更できる jquery プラグインを使用しています。したがって、私の目標は、オブジェクトのリスト (AlertInfo) を取得し、それを JavaScript 関数で使用できるようにすることです。テスト プロジェクトで json webservice 呼び出しを使用して、データをページに渡すことができました。しかし、現在 Web サービス ページがないため、aspx.cs ページから取得しようとしましたが、うまくいきませんでした。
///Apx ページ:
$.ajax({
type: "POST",
url: "~/Alerts/GetAlerts",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
var data = eval("(" + msg.d + ")");
jQuery.each(data, function (rec) {
AlertList[AlertList.length] = new objAlert(this.id, this.title, this.details, JSONDateSerializationFix(this.startdate), JSONDateSerializationFix(this.enddate));
UpdateDisplayList();
})
},
error: function (msg) {
alert("BRAD" + msg);
}
問題は、"URL /Alerts/GetAlerts" のアラート ページが Alerts.aspx.cs であることです。この ajax コマンドを使用して aspx.cs ページのメソッドを呼び出せるかどうかわかりません。
// コード ビハインド ページ aspx.cs
[WebMethod]
//[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public string GetAlerts()
{
List<AlertInfo> list = AlertInfo.GetTestAlerts();
return new JavaScriptSerializer().Serialize(list);
}
public List<AlertInfo> GetAlertsList()
{
List<AlertInfo> list = AlertInfo.GetTestAlerts();
return list; ;
}
だから私はデータをaspコントロール(dataList)にロードしてからデータを取得できることを望んでいました
// コード ビハインド ページ
protected void Page_Load(object sender, EventArgs e)
{
dataListAlertList.DataSource = GetAlertsList();
dataListAlertList.DataBind();
}
public static List<AlertInfo> GetTestAlerts()
{
List<AlertInfo> list = new List<AlertInfo>();
list.Add(new AlertInfo("0", "Alert 1 Title", "Alert 1 Detail", "10/10/2010", "10/10/2011"));
list.Add(new AlertInfo("1", "Alert 2 Title", "Alert 2 Detail", "10/10/2010", "10/10/2011"));
return list;
}
//.aspx ページ
$(document).ready(function () {
var a1 = $("#dataListAlertList").val();
// do fun stuff now.
}
しかし、私は未定義になり続けます....