2012-07-07 135 views
0

嗨,大家好我有一个表单提交后链接到一个脚本“sendeveryone.php”这个脚本需要相当长的一段时间才能完成,所以我想显示一个加载图像,而这样做,怎么可能我做到了?在php脚本之前加载图像

谢谢

+0

向我们展示一些您已拥有的代码。 – Thew 2012-07-07 16:13:07

+1

或者你可以尝试和同行到这个答案提示如何做你想要做的事情:http://stackoverflow.com/questions/7692633/how-to-showloading-gif-while-iframe -is-loading-up-a-website – abelito 2012-07-07 16:13:50

回答

1

在提交后,您可以使用javascript显示加载图像。 将onclick="showLoading()"属性放入您的提交按钮中,并创建一个showLoading()javascript函数。

0

你有2种选择: 要么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 ! 

    } 
} 
+0

好班!收藏它。 – Thew 2012-07-07 16:22:38

+0

乐意帮忙,我会把它上传到我的博客... – 2012-07-07 16:24:33

+0

有点棘手,但是...我更喜欢Ajax的选择,无论如何 – 2012-07-07 16:26:14

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的方法,但是看着您的文章的写作风格,我不认为你这个先进。

相关问题