我有一个.NET Web服务,它必须执行几个操作,我想通过回调到javascript函数显示进度。
这是功能
“//vb.NET
<WebMethod(EnableSession:=True)> _ <ScriptMethod(ResponseFormat:=ResponseFormat.Json, XMLSerializeString:=False)> _ Public Shared Function RebuildLuceneIndex(options As List(Of RebuildLuceneOption), callbackProgress As Action(Of String, Boolean)) For Each opt As RebuildLuceneOption In options Try Select Case opt.Action.ToLower() Case "clear" ....... End Select callbackProgress.Invoke(opt.Action.ToLower(), True) Catch ex As Exception callbackProgress.Invoke(opt.Action.ToLower(), False) End Try Next End Function我正在努力研究jQuery语法来调用这个webservice传递一个json数组的字符串,并回调函数,然后我可以回调它来显示进度。
// JavaScript的
function RebuildLuceneProgressCallback(InvokedMethod, Successfull) { if (Successfull) { console.log(InvokedMethod + ' Succeeded'); } else { console.log(InvokedMethod + ' Failed'); } }I have a .NET webservice which has to perform several actions and I would like to display progress via a callback to a javascript function.
this is the function
'//vb.NET
<WebMethod(EnableSession:=True)> _ <ScriptMethod(ResponseFormat:=ResponseFormat.Json, XMLSerializeString:=False)> _ Public Shared Function RebuildLuceneIndex(options As List(Of RebuildLuceneOption), callbackProgress As Action(Of String, Boolean)) For Each opt As RebuildLuceneOption In options Try Select Case opt.Action.ToLower() Case "clear" ....... End Select callbackProgress.Invoke(opt.Action.ToLower(), True) Catch ex As Exception callbackProgress.Invoke(opt.Action.ToLower(), False) End Try Next End FunctionIm struggling to workout the jQuery syntax for calling this webservice passing a json array of strings, and a callback to the function which i can then callback into to show progress.
//javascript
function RebuildLuceneProgressCallback(InvokedMethod, Successfull) { if (Successfull) { console.log(InvokedMethod + ' Succeeded'); } else { console.log(InvokedMethod + ' Failed'); } }最满意答案
您需要将方法拆分为两种方法:Begin&End。 请参阅有关服务器端异步Web方法的这篇文章。
然后在你的jQuery调用中,你需要调用Begin()方法,然后是后续的请求来检查方法是否已经完成。
You need to split your method up into two methods: Begin & End. See this article on Server-Side Asynchronous Web Methods.
Then in your jQuery call, you need to call the Begin() method, followed by subsequent requests to check if the method has finished.
更多推荐
发布评论