asp.net call WebMethod from Javascript asyncronous

后端 未结 2 1358
没有蜡笔的小新
没有蜡笔的小新 2020-12-06 15:01

I am trying to build an asp.net(c#) page that updates some state texts every second. Now I have implemented an button that calls another PageMethod which restarts something

2条回答
  •  再見小時候
    2020-12-06 15:40

    you should call the page methods using an Async call instead.

    have a look at the below. It is a generic way to call a page method using JQuery

    $.ajax({
      type: "POST",
      url: "PageName.aspx/MethodName",
      data: "{}",
      contentType: "application/json; charset=utf-8",
      dataType: "json",
      success: function(msg) {
        // Do something interesting here.
      }
    });
    

    you should use this code to replace the page method calls

    PageMethods.Restart(function (text))
    
    PageMethods.Update(function (text))
    

提交回复
热议问题