嗯即時嘗試返回比字符串或布爾型更復雜的類型,但我失敗了我做錯了什麼? 的JavaScriptJQuery和ASP.Net
<script language="javascript" type="text/javascript">
///<Reference Path="~/Script/jquery-1.3.2-vsdoc.js" />
$(document).ready(function() {
// Add the page method call as an onclick handler for the div.
$("#Result").click(function() {
$.ajax({
type: "POST",
url: "Test.aspx/GetDate",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
// Replace the div's content with the page method's return.
$("#Result").text(msg.Name);
},
failure: function() { alert("Failed") }
});
});
});
</script>
C#(這不是一個web服務只是一個正常的網頁)
[WebMethod]
public static ImageDC GetDate()
{
ImageDC dc = new ImageDC();
dc.Id = 1;
dc.Name = "Failwhale";
dc.Description = "Hurry the failwale is going to eat us!";
dc.IsPublic = true;
return dc;
}
所以我必須創建一個webservce?它似乎跛腳,如果我想讓網頁被迫創建一個web服務只是爲了juse ajax? :( – Peter 2009-05-27 21:56:18