< WebMethod()> 公开 共享 功能 myFunct(par1 as string ) as string //在这里做一些代码 end 功能
解决方案
.ajax({ type:POST, contentType:application / json; charset = utf-8, dataType:json, async:true, cache:false, data:{myparameters}, url:myFunct成功:回调 }); < / script> File2.js < script>
.ajax({ type:POST, contentType: application / json; charset = utf-8, dataType:json, async:true, cache:false, data:myparameters, url:myFunct成功:回调 }); < / script>
< WebMethod()> 公开 共享 功能 myFunct(par1 as string ) as string //在这里做一些代码 end 功能
最可能的问题是您启用了会话状态。即使您的方法从未触及会话状态,如果它已为请求处理程序(页面)启用,则对具有相同会话ID的该处理程序的所有请求都将被序列化。 如果可能,请关闭页面的会话状态: <%@ Page ... EnableSessionState =False%>
如果您需要从会话中读取数据,您可以将其设为只读:
<%@ Page ... EnableSessionState =ReadOnly%>如果页面的其他部分需要写入会话,那么你''我需要将方法移动到一个单独的处理程序,并禁用该处理程序的会话状态。 如果你的方法需要将数据写入会话,那么你什么都没有可以做。 ASP.NET会话状态概述| Microsoft Docs [ ^ ]
Hallo evrybody , i am trying to make some operations simultaneously at the same time per Ajax ,to search some data in Database, but somehow it doesn't work , cause the server is treating each request individually !! is that anyway possible ? What I have tried:
File1.js <pre lang="Javascript"><script> $.ajax({ type: "POST", contentType: "application/json; charset=utf-8", dataType:"json", async: true, cache:false, data: "{myparameters}", url: "myFunct" success: callback }); </script> File2.js <script> $.ajax({ type: "POST", contentType: "application/json; charset=utf-8", dataType:"json", async: true, cache:false, data: "myparameters", url: "myFunct" success: callback }); </script><WebMethod()> Public Shared Function myFunct (par1 as string) as string //do some code here end Function 解决方案 .ajax({ type: "POST", contentType: "application/json; charset=utf-8", dataType:"json", async: true, cache:false, data: "{myparameters}", url: "myFunct" success: callback }); </script> File2.js <script>.ajax({ type: "POST", contentType: "application/json; charset=utf-8", dataType:"json", async: true, cache:false, data: "myparameters", url: "myFunct" success: callback }); </script>
<WebMethod()> Public Shared Function myFunct (par1 as string) as string //do some code here end FunctionThe most likely issue is that you have session state enabled. Even if your method never touches the session state, if it's enabled for the request handler (the page), all requests to that handler with the same session ID will be serialized. If possible, turn off session state for the page: <%@ Page ... EnableSessionState="False" %>
If you need to read data from the session, you might be able to get away with making it read-only:
<%@ Page ... EnableSessionState="ReadOnly" %>If other parts of your page need to write to the session, then you'll need to move the method to a separate handler, and disable session state for that handler. If your method needs to write data to the session, then there's nothing you can do. ASP.NET Session State Overview | Microsoft Docs[^]
更多推荐
使webmethod异步
发布评论