等待时显示加载动画


Displaying loading animation while waiting

我有一个类似的按钮

{!! link_to_route('jobs.createJob', 'Create Job', $job->id, array('class' => 'btn btn-info')) !!}

所以这个路由调用了一个函数,它做一些类似的事情

public function createJob(Job $job) {
    $createJob = Helper::createNewJob($job);
    $createJobXML = new 'SimpleXMLElement($createJob);
    if($createJobXML->Status == 'OK') {
        $job->jobNumber = $createJobXML->Job->ID;
        if($job->update()) {
            $assignStaff = Helper::assignStaffToJob($job);
            $assignStaffXML = new 'SimpleXMLElement($assignStaff);
            if($assignStaffXML->Status == 'OK'){
                $createQuoteForJob = Helper::createQuoteForJob($job);
                $createQuoteForJobXML = new 'SimpleXMLElement($createQuoteForJob);
                if($createQuoteForJobXML->Status == 'OK'){
                    $job->quoteId = $createQuoteForJobXML->ID;
                    if($job->update()) {
                        return View::make('jobs.show', compact('job'));
                    }
                }
            }
        }
    }
    return View::make('campaigns.show', compact('job'));
}

因此,有相当多的事情需要点击几个API方法来将数据插入系统。这个过程有时可能需要几秒钟,我不希望他们能够再次单击提交按钮,所以我想在发生这种情况时向他们显示一个加载屏幕。

如果我是通过ajax发出这个请求的,我可以简单地使用ajaxStart和ajaxComplete。然而,我没有使用ajax,那么在Laravel 5中还有其他方法可以做到这一点吗?

感谢

向按钮添加onclick处理程序,以便在单击时禁用它。

{!! link_to_route('jobs.createJob', 'Create Job', $job->id, array('class' => 'btn btn-info', 'onclick' => 'disableButton(this)')) !!}
function disableButton(ele)
{
    ele.disabled = true;
    // And display loading animation here if you need.
}