문제

나는 jQuery 초보자이며 jQuery 스크립트에 Pagemethod의 결과를 읽으려고 노력합니다. ScriptManager가 설치되어 있으며 다음 웹 메드가 있습니다.

[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";
    }

객체에 속성이 있는지 확인하기 위해 이것을 사용합니다.

스크립트에서 URL에서 ID를 넘겨 결과를 평가하려고합니다.

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

그러나 결과적으로 변수 "점검"은 정의되지 않습니다. 무엇을 변경해야합니까?

도움이 되었습니까?

해결책 2

내 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>

다른 팁

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

<ajaxToolkit:ToolkitScriptManager runat="Server"
    EnableScriptGlobalization="true"
    EnableScriptLocalization="true"
    ID="ScriptManager1"
    EnablePageMethods="true"/>
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top