所以我使用了一个 jquery 插件,它允许我通过拖放来更改列表中事物的顺序。所以我的目标是能够获取我的对象列表 (AlertInfo) 并在 javascript 函数中使用它。我能够在测试项目中使用 json webservice 调用将数据传递到页面。但是我们现在没有 web 服务页面,所以我尝试从 aspx.cs 页面中获取它,但没有成功。
///aspx页面:
$.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.
}
但我一直不确定....