【问题标题】:How to handle time consuming webservice operation through Javascipt Callbacks如何通过 Javascript Callbacks 处理耗时的 Web 服务操作
【发布时间】:2020-04-17 02:13:32
【问题描述】:

我在我的一个 Web 应用程序中执行以下操作。我有一个返回值的函数。该值应传递给一个单独运行到我的 Web 应用程序的 Web 服务方法。此 Web 服务操作需要一些时间才能完成,因此必须在后台运行,并在完成后返回一条消息。我想通过 Javascript 回调来做到这一点。代码基本流程如下;

 Dim shr_intfB_Common_LCI As clsCreamsCommon
 Dim stringResult As StringResult
 shr_intfB_Common_LCI = New clsCreamsCommon
 Call shr_intfB_Common_LCI.CreamsBooking(clsTapsCreamsPropsDtl,
                               intRetCode, strMessage, intRequestId
                               )

// This intRequestId needs to be passed to the following web service.
Do
   Threading.Thread.Sleep(10 * 1000) '10 Second
   stringResult = objService.CheckRequestStatus(objServiceUser, intRequestId)
   Loop Until stringResult Is Nothing Or stringResult.ReturnCode <> 2    

//The stringResult includes the followings which I have to display. 
MessageBox(Me, stringResult.ReturnCode, stringResult.ReturnData + stringResult.ReturnMessage)

我想在不使用线程或任务的情况下执行此操作,因为这是一个 Web 应用程序,但使用 JavaScript 回调。请帮帮我。

【问题讨论】:

    标签: javascript asp.net ajax web-services


    【解决方案1】:

    要在 JavaScript 中建立回调函数,可以使用 jQuery ajax 或 PageMethods 调用

    两个选项会分开运行,一旦web方法执行完毕,会返回,成功或失败回调

    JavaScript 中的页面方法

    https://www.codeproject.com/Questions/631342/Calling-csharp-function-in-javascript

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-02
      • 1970-01-01
      • 2011-09-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多