2013-07-10 2 views
2

입니다 자바 스크립트 아약스 코드웹 서비스가 여기에 JSON

$(document).ready(function() { 
     $.ajax({ 
      url: "Service/HelloWorld.asmx/Hello", 
      dataType: 'json', 
      type: 'POST', 
      cache: false, 
      crossDomain: true, 
      timeout: 15000, 
      success: function (rtndata) { 
       alert('Success : :' + rtndata); 
      }, 
      error: function (xhr, errorType, exception) { 
       alert("Excep:: " + exception + "Status:: " + xhr.statusText); 
      } 
     }); 
    }); 

얻기 오류 다음은 웹 서비스

public class HelloWorld : System.Web.Services.WebService 
{ 

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

입니다

Excep:: Invalid JSON: <?xml version="1.0" encoding="utf-8"?> 
<string xmlns="http://tempuri.org/">Hello World</string>Status:: OK 

답변

0

web.config의 처리기 섹션에서 ScriptHandlerFactory 설정을했는지 확인하십시오.

<httpHandlers> 
    <remove verb="*" path="*.asmx"/> 
    <add verb="*" path="*.asmx" validate="false" 
      type="System.Web.Script.Services.ScriptHandlerFactory, 
      System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, 
      PublicKeyToken=31bf3856ad364e35"/> 
</httpHandlers> 

자세한 내용은 아래 링크를 체크 아웃 :

http://www.asp.net/web-forms/tutorials/aspnet-ajax/understanding-asp-net-ajax-web-services

편집

난 당신이 설치 및 구성 실수에 대해 설명 데이브 워드의 블로그 게시물 아래로 통과 것을 제안

:

http://encosia.com/asmx-scriptservice-mistakes-installation-and-configuration/

0

를 사용해보십시오
[ScriptMethod(UseHttpPost=true, ResponseFormat=ResponseFormat.Json)] 

서비스에서 개체를 반환하여 클라이언트에서 더 예측 가능하게 사용할 수 있도록합니다.

return new Result() { Value = "some string" }; 
관련 문제