asp.net call WebMethod from Javascript asyncronous

后端 未结 2 1356
没有蜡笔的小新
没有蜡笔的小新 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:36

    It's because an Request only Proceeds when no other Request is processing. Thats because two Processes can't acess to the same SessionState (Sessionstate is not Threadsafe).

    So to achieve that Requests are processed at the same time, you have to set EnableSessionState in the @Page directive to either 'ReadOnly' or 'false'

    0 讨论(0)
  • 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))
    
    0 讨论(0)
提交回复
热议问题