0

在我的通用处理程序中,我使用 RestSharp 执行异步 HTTP POST,然后在等待 POST 请求返回之前向用户显示一些 html。然后,一旦 Http 响应返回,我想通过注入一些 Javascript 来显示一条消息。

var asyncHandle = client.ExecuteAsync(request, response =>
    {
       if (response.StatusCode == HttpStatusCode.OK)
       {
           //here I would like to display a notification to the user but the handler already returned processedHtml at this point
           context.Response.Write(@"<script type='text/javascript'>
                                                window.parent.$.gritter.add({
                                                    text: 'some message',
                                                    time: 20000,
                                                    sticky: false
                                                });</script>");
       }
    });

//this line executes before waiting for response from async call
context.Response.Write(processedHtml);

问题是,此时生命周期已经结束,因此 context.Response.Write(@"<s​​cript ... ") 生成“对象引用未设置为对象实例”。当异步响应返回时,还有其他方法可以注入 javascript 吗?

4

0 回答 0