2010-03-12 6 views
0

저는 꽤 jQuery 초보자이며 PageMethod의 결과를 내 jQuery 스크립트로 읽으려고합니다. ScriptManager가 설치되어 있고 다음 웹 메소드가 있습니다.PageMethod의 결과를 jQuery 스크립트로 읽어들입니다.

[WebMethod(EnableSession = true)] 
    public static string CheckSystemDefault(string _id) 
    { 
     int id = Convert.ToInt16(_id); 
     addressTypeRepository = new AddressTypeRepository(); 

     AddressType addressType = addressTypeRepository.GetById(id); 

     if (addressType.IsSystemDefault == true) 
      return "IsSystemDefault"; 
     else 
      return "IsNotSystemDefault"; 
    } 

객체를 IsSystemDefault 속성이 있는지 확인하는 데 사용합니다.

스크립트에서, 나는 URL의 ID를 넘겨 및 결과 평가하려는 :

var id = $(document).getUrlParam("id"); 
var check = PageMethods.CheckSystemDefault(id); 
if (check == "IsSystemDefault") { 
... 
} 
if (check == "IsNotSystemDefault") { 
... 
} 

을하지만 결과, 변수가 "확인"정의되지 않습니다. 무엇을 바꾸어야합니까?

+0

, 당신은 그 중단 점을 명중 않으며, 오류없이 완전한 웹 방법을합니까? –

+0

나는 브레이크 포인트에 결코 충돌하지 않았다. – AGuyCalledGerald

답변

0

내 jQuery 스크립트의 구문이 올바르지 않습니다.

그것은 다음과 같은 수 있습니다 : 웹 방법에 중단 점으로 디버깅 할 때

<script type="text/javascript"> 

    jQuery(document).ready(function() { 

     var id = $(document).getUrlParam("id"); 

     PageMethods.CheckSystemDefault(id, function(result) { 
      if (result == "IsSystemDefault") 
       // do something 
      else 
       // do something 
     }); 

    });  

</script> 
0

스크립트 관리자에서 페이지 메서드를 활성화해야합니다. 아래 마지막 속성이 표시되면 스크립트 관리자 요소에서 EnablePageMethods = "true"를 지정 했습니까?

<ajaxToolkit:ToolkitScriptManager runat="Server" 
    EnableScriptGlobalization="true" 
    EnableScriptLocalization="true" 
    ID="ScriptManager1" 
    EnablePageMethods="true"/> 
+0

예, 지정했습니다. – AGuyCalledGerald

관련 문제