使webmethod异步 [英] Make webmethod async

查看:95
本文介绍了使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异步的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆