まあ私は文字列やブールより複雑な型を返そうとしていますが、私は何が間違っているのですか? JavaScriptのJQueryと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#(これは普通のウェブページのウェブサービスではありません)
[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サービスを作成してAJAXを作成する必要がある場合は不自然に思えます。 : – Peter
Im running .net 3.5 – Peter
msg.d.Nameを追加してくれてありがとうございます。それは魅力的でしたが、私はいつも.d。を追加する必要がありますか?: – Peter