Yii框架异步请求框架、Yii

由网友(谢谢赠我空欢喜)分享简介:我有AJAX请求做3任务:I have ajax request that do 3 missions: 在保存模型(DB)发送电子邮件提供成功或失败的消息。 由于这个任务需要太长的时间。用户可以等待长达20秒的响应(成功或失败的消息)。并且如果用户关闭浏览器其停止在操作该电流过程对于用户中的一个。 Becau...

我有AJAX请求做3任务:

I have ajax request that do 3 missions:

在保存模型(DB) 发送电子邮件 提供成功或失败的消息。

由于这个任务需要太长的时间。用户可以等待长达20秒的响应(成功或失败的消息)。并且如果用户关闭浏览器其停止在操作该电流过程对于用户中的一个。

Because this mission takes too time. User can wait up to 20 sec for response (success or failed message). And if the user close the browser its stop in one of the operation that current process for the user.

这是不好的用户体验。

This is bad user experience.

我希望用户提交自己的数据,我的控制器和之后,他将获得成功或失败的消息。并且该过程将完全在服务器侧和它应支持多会话

I want user submit his data to my Controller and after it he will get the "success or failed message". And the process will be completely in the server side and its should support multi sessions.

我怎么能这样做?

推荐答案

@hakre你给没有减少什么时候用户等待响应。

@hakre What you gave not reduce the time user wait for respond.

我发现这样做的最好的解决办法: runactions扩展警予

I found the best solution for this: runactions extension for yii

这是扩展让你从控制器后台操作运行。 有几种方式来使用它。最好的一个我的情况是这样的。

This is extension let you run from controller background actions. There are several way to use it. The best one for my case is this

public function actionTimeConsumingProcess()
{
    if (ERunActions::runBackground())
    {
       //do all the stuff that should work in background
       mail->send()
    }
    else
    {
        //this code will be executed immediately
        //echo 'Time-consuming process has been started'
        //user->setFlash ...render ... redirect,
    }
  //User information
  echo "Submit Success!"
}

和它的工作,但没有Ajax请求,当我做Ajax请求其不工作的某些原因。 所以我用:

And its work but without ajax request, When I make ajax request its not working for some reason. So I used:

                         ERunActions::httpPOST($this->createAbsoluteUrl('Form/Submit'), array('to'=>'mail@domain.com', 'subject'=>'This is the subject'));

和它的工作很大,但它不是为这个理想的解决方案。

And its work great but its not the ideal solution for this.

阅读全文

相关推荐

最新文章