Javascript Web服务能否将回调函数作为参数?
我有一个.NETWebService,它必须执行几个操作,我希望通过回调javascript函数来显示进度 这就是函数 '//vb.NETJavascript Web服务能否将回调函数作为参数?,javascript,jquery,asp.net,Javascript,Jquery,Asp.net,我有一个.NETWebService,它必须执行几个操作,我希望通过回调javascript函数来显示进度 这就是函数 '//vb.NET <WebMethod(EnableSession:=True)> _ <ScriptMethod(ResponseFormat:=ResponseFormat.Json, XMLSerializeString:=False)> _ Public Shared Function RebuildLucene
<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调用中,需要调用Begin()方法,然后是后续的请求,以检查该方法是否已完成
function RebuildLuceneProgressCallback(InvokedMethod, Successfull) {
if (Successfull) {
console.log(InvokedMethod + ' Succeeded');
}
else {
console.log(InvokedMethod + ' Failed');
}
}