我想對代碼隱藏文件上的靜態方法進行jquery ajax調用。問題是由Spring注入的ArtistManager不是靜態的,我不能在靜態web方法中使用它。我要尋找關於如何實現這一spring.net + nhibernate + jquery ajax在代碼隱藏中調用webmethod
ArtistList.aspx
$(document).ready(function() {
$("#Result").click(function() {
$.ajax({
type: "POST",
url: "ArtistList.aspx/GetArtists",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
$("#Result").text(msg.d);
alert("Success: " + msg.d);
},
error: function (msg) {
// Replace the div's content with the page method's return.
$("#Result").text(msg.d);
alert("Error: " + msg.d);
}
});
});
});
ArtistList.aspx.cs
private IArtistManager artistManager;
public IArtistManager ArtistManager
{
set { this.artistManager = value; }
get { return artistManager; }
}
protected long rowCount = 0;
.
.
.
[WebMethod]
public static IList<App.Data.BusinessObjects.Artist> GetArtists()
{
//return ArtistManager.GetAll("Name", "ASC", 1, 100, out rowCount);
}
GetArtists()爲什麼是靜態方法? – Marijn 2011-01-30 12:38:16
明白了 - 靜態是允許ASPX頁面中的ASP.NET AJAX回調Web方法,閱讀它[這裏](http://geekswithblogs.net/frankw/archive/2008/03/13/asp.net- ajax-callbacks-web-methods-in-aspx-pages.aspx) – Marijn 2011-01-30 13:16:33