글자 나 문자열이나 부울보다 복잡한 형식을 반환하려고하지만 내가 뭘 잘못하고 있습니까? 자바 스크립트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;
}
그래서 웹 서버를 만들어야합니까? 내가 웹 페이지를 만들어서 juse ajax에 웹 서비스를 만들어야한다면 안좋은가 보군? : – Peter
임 실행 중 .net 3.5 – Peter
msg.d.Name을 추가 한 경우 참 감사합니다. 매력처럼 작동하지만 항상 all .d. 지금 추가해야합니까? : – Peter