嗯即时尝试返回比字符串或布尔型更复杂的类型,但我失败了我做错了什么? 的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