Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/84.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Web服务能否将回调函数作为参数?_Javascript_Jquery_Asp.net - Fatal编程技术网

Javascript Web服务能否将回调函数作为参数?

Javascript 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

我有一个.NETWebService,它必须执行几个操作,我希望通过回调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调用中,需要调用Begin()方法,然后是后续的请求,以检查该方法是否已完成

function RebuildLuceneProgressCallback(InvokedMethod, Successfull) {
    if (Successfull) {
        console.log(InvokedMethod + ' Succeeded');
    }
    else {
        console.log(InvokedMethod + ' Failed');
    }        
}