使webmethod异步

编程入门 行业动态 更新时间:2024-10-19 01:26:40
本文介绍了使webmethod异步的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 Hallo evrybody, i我试图同时进行一些操作每个Ajax ,搜索数据库中的一些数据, 但不知何故它不起作用,因为服务器正在单独处理每个请求!! 无论如何可能吗? 我尝试过:

File1。 js < pre lang =Javascript>< script> $ .ajax({类型:POST, contentType:application / json; charset = utf-8, dataType:json, async:true, cache:false, data:{myparameters}, url:myFunct成功:回调 } ); < / script> File2.js < script> $ .ajax({类型:POST, contentType:application / json; charset = utf-8, dataType:json, async:true, cache:false, data:myparameters, url:myFunct success:callback }); < / script>

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

The 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异步

本文发布于:2023-11-13 00:35:14,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1582922.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:webmethod

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!