2012-05-31 3 views
0

메트로 UI 앱을 시작하기 전에 json 데이터를 사용하여 반환하려고합니다. 내 웹 서비스가 json 데이터를 반환하지는 않지만 항상 XML 데이터를 retunr합니다. 일부는 이것에 도움이 될 수 있습니다.웹 서비스가 json 데이터를 반환하지 않습니다.

<html xmlns="http://www.w3.org/1999/xhtml" > 
<head> 
    <title>Untitled Page</title> 
    <script language="javascript" type="text/javascript"> 

     var req = new XMLHttpRequest(); 
     xmlhttp.setRequestHeader("Content-Type", "application/json"); 

     function Roll() { 
      if (req.readyState == 4) { 
       alert(req.responseText); 
       alert("exiting"); 
      } 
     } 

     function Test() { 
      alert("starting"); 
      req.open("POST", "http://localhost:58718/testService/Service.asmx/HelloWorld", true); 
      req.onreadystatechange = Roll; 
      req.send(null); 
     } 


    </script> 
</head> 
<body> 

    <button onclick="javascript:Test()">TEST</button> 
</body> 
</html> 

답변

0

[WebMethod] 
    [ScriptMethod(ResponseFormat = ResponseFormat.Json)] 
    public string HelloWorld() { 
     return "Hello World"; 
    } 

HTML 페이지는 웹 구성 파일에 추가합니다.

<httpHandlers> 
<remove verb="*" path="*.asmx"/> 
<add verb="*" path="*.asmx" type="System.Web.Script.Services.ScriptHandlerFactory" validate="false"/> 
</httpHandlers> 

믿음 슬로안

+0

이 라인은 내 web.config 파일에 기본적으로 존재한다. 프레임 워크 버전 3.5를 사용하고 있습니다. – Kurkula

관련 문제