2009-05-27 4 views
1

글자 나 문자열이나 부울보다 복잡한 형식을 반환하려고하지만 내가 뭘 잘못하고 있습니까? 자바 스크립트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; 
} 

답변

2

실행중인 .NET 버전은 확실하지 않지만 웹 서비스에서 반환 된 개체의 변경 사항이 있습니다. 이 기사를 확인하십시오. 당신이 요청/응답을보고 피들러를 사용하는 경우

http://encosia.com/2009/02/10/a-breaking-change-between-versions-of-aspnet-ajax/

,이 문제의 경우 쉽게 알 수 있어야합니다.

http://www.fiddler2.com/fiddler2/

+0

그래서 웹 서버를 만들어야합니까? 내가 웹 페이지를 만들어서 juse ajax에 웹 서비스를 만들어야한다면 안좋은가 보군? : – Peter

+0

임 실행 중 .net 3.5 – Peter

+0

msg.d.Name을 추가 한 경우 참 감사합니다. 매력처럼 작동하지만 항상 all .d. 지금 추가해야합니까? : – Peter

-1

(이것은 웹 서비스 단지 일반 웹 페이지 아닙니다).