Using JQuery to call a WebMethod

后端 未结 2 1779
我寻月下人不归
我寻月下人不归 2020-12-09 05:31

I am having trouble getting inside my Search WebMethod from my JQuery call. Maybe someone could help to point me in the right direction.

I also packed up everything

2条回答
  •  忘掉有多难
    2020-12-09 06:17

    You need to do the following (C#):

    • The WebMethod must be public static
    • It must be decorated with the [WebMethod] attribute
    • You need a ScriptManager on your .aspx page
    • Set the ScriptManager's EnablePageMethods="true"

    And here is some sample javascript:

    $().ready(function() {
        $(yourDropDownList).change(LoadValues);
    });
    
    
    function LoadValues() {
        PageMethods.YourMethod(arg1, CallSuccess, CallFailed);
    }
    
    function CallFailed(result) {
        alert('AJAX Error:' + result.get_message());
    }
    
    function CallSuccess(result) {
        //do whatever you need with the result
    }
    

提交回复
热议问题