在php脚本之前加载图像

时间:2012-07-07 16:10:09

标签: php image loading

大家好我有一个表单,在提交了一个脚本“sendeveryone.php”的链接后,这个脚本需要很长时间才能完成,所以我想在完成时显示一个加载图像,我怎么能实现这个? / p>

由于

3 个答案:

答案 0 :(得分:1)

在提交时,您可以使用javascript显示加载图片。 将onclick="showLoading()"属性放入提交按钮,然后创建showLoading()javascript函数。

答案 1 :(得分:0)

你有两个选择: 要么ajax调用脚本,要么在客户端运行一些显示进度的js 或者你可以在php中返回一个响应并继续执行我的以下代码片段

/*
 * basically allow a php script to return a response and continue with
 * code execution, good for statistics.
 * before echo anything to user call begin and after call end, than you can continue doing stuff
 */
class ScriptContinuationManager
{
    /**
     * this is the point where we need to give a sign to this class
     * that we wanna write our response.
     * @return void
     */
    public function beginRespone()
    {
        ob_end_clean();
        header("Connection: close");
        ignore_user_abort(); // optional
        ob_start();

    }

    /*
     * after this function execution the response will be sent to the
     * client, and code continue without client need to wait.
     */
    public function endResponse()
    {
        $size = ob_get_length();
        header("Content-Length: $size");
        ob_end_flush(); // Strange behaviour, will not work
        flush(); // Unless both are called !

    }
}

答案 2 :(得分:0)

尝试使用javascript解决方案:

这将隐藏提交按钮并显示图像。您需要自己选择加载图像,可以在http://ajaxload.info/生成加载图像。此外,您还必须为表单提供ID属性,并将其放在脚本中。

(确保包含jQuery)

var formid = ''; // What is the ID of the form? (without the #)
var imgpath = ''; // What is the path to the loading image you want to display?

$(document).ready(function(event){  
    $('#'+ formid).submit(function(event){
        $('#'+ formid +' input[type=submit]').after('<img src="'+ imgpath +'">').hide();
    });
});

编辑:我也建议使用AJAX方法,但看看你的帖子的写作风格我不认为你是那么先进。