Asynchronous 在泛型处理程序中从异步方法注入JavaScript

Asynchronous 在泛型处理程序中从异步方法注入JavaScript,asynchronous,httphandler,restsharp,Asynchronous,Httphandler,Restsharp,在我的通用处理程序中,我使用RestSharp执行异步HTTP POST,然后在等待POST请求返回之前向用户显示一些html。然后,一旦Http响应返回,我想通过注入一些Javascript来显示一条消息 var asyncHandle = client.ExecuteAsync(request, response => { if (response.StatusCode == HttpStatusCode.OK) { //her

在我的通用处理程序中,我使用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);
var asynchHandle=client.ExecuteAsync(请求,响应=>
{
if(response.StatusCode==HttpStatusCode.OK)
{
//这里我想向用户显示一个通知,但处理程序此时已经返回processedHtml
context.Response.Write(@)
window.parent.$.grister.add({
文本:“一些消息”,
时间:20000,
粘性:假
});");
}
});
//该行在等待异步调用的响应之前执行
context.Response.Write(processedHtml);

问题是,到那时,生命周期就结束了,所以context.Response.Write(@"嗯,当然,行执行时,您执行了一个异步调用,所以没有任何东西等待该代码。这就是定义。为什么不在异步调用完成时调用一个函数呢?这就是我试图做的;但是,在这一点上,处理程序已经完成了它的生命周期,所以我不能使用context.response注入任何Javascripte、 您可以使用JQuery的$.ajax函数,它允许您设置一个函数,以便在完成时调用结果。否则,请在Javascript文档中搜索类似的内容。