页面加载后运行PHP [英] Run PHP After Page Loads up

查看:105
本文介绍了页面加载后运行PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近创建了一个Facebook应用程序,该应用程序向用户组发布了一些内容.如果用户发布到多个组,那么我想显示一个进度栏.它的HTML部分创建了一个具有文本区域的表单,该表单重定向到post.php文件.我在该post.php页面中发布给用户组.正如我所说,我使用进度条显示进度.但是消息首先发布,然后进度条才起作用.我非常确定它的进度条是否有效.

I created a facebook app recently that posts some content to the user group. If the user posts to multiple groups then I would like to display a progress bar. The HTML part of it I created a form that has got a text area and the form redirects to a post.php file. And I post to the user groups in that post.php page. As I said I use a progress bar to show the progress. But the message gets posted first and only then the progress bar works. I'm pretty sure about the progress bar that it works.

简而言之,PHP部分首先在JS或HTML之前执行.因此,请帮助我解决这个问题.

To put it short the PHP part gets executed first before the JS or the HTML. So please do help me out in overcoming this problem.

这就是post.php文件中的内容:

This is what I have in the post.php file :

    <body style = "background-color: #4ea6e6;">
    <center>
        <div style = "width: 50%; margin-top: 5%; padding: 50px; background-color: #fff;">
            <div class="input-group" style = "height: 30px;">
                <progress min = "0" max = "100" value = "50" style = "height: 30px;">

                </progress>

                <span class="input-group-addon">
                    0%
                </span>
            </div>

            <br>
            <div class = "message">

            </div>

            <br>
            <div class = "alert alert-success success" style = "font-size: 18px; font-family: Muli; visibility: hidden;"><b>Great !</b> Your message was successfully posted !</div>

        </div>

    </center>
</body> <?php

    require_once 'libs/facebook.php';
    $config = array(
      'appId' => 'My app id',
      'secret' => 'my app secret',
      'fileUpload' => false, // optional
      'allowSignedRequest' => false, // optional, but should be set to false for non-canvas apps
    );

    $facebook = new Facebook($config);
    $groups = $_POST['groups'];
    $link = $_POST['link'];
    $message = $_POST['message'];
    $count = count($groups);

    for($i=1; $i<count($groups); $i++){

                $api = $facebook->api($groups[$i] . '/feed', 'post', array(
                    link => $link,
                    message => $message
                ));

                $api = $facebook->api($groups[$i]);

                $name = $api['name'];

                $j = ($i/(count($groups)-1))*100;

                ?>

                <script type = "text/javascript">
                var timeout = setTimeout(post, 0);
                function post(){

                    $('progress').attr("value" , "<?php echo $j; ?>");
                    $('.message').html("Posting to <?php echo $name; ?>");
                    $('.input-group-addon').html("<?php echo $j; ?> %");

                    if(<?php echo ($i/count($groups)); ?> != 1){
                        var timeout = setTimeout(post, 0);
                    }
                    else{
                        clearTimeout(timeout);
                    }
                }

                </script>
                <?php

            }

推荐答案

您可以在页面加载后执行一个单独的PHP文件,而无需使用JS,就像这样.

You can execute a separate PHP file after the page has loaded, without JS, like this.

请注意,背景图像"实际上是一个PHP文件.该PHP文件将在正文底部,html文件及其上方的所有元素之后被调用时执行.

Notice that the "background image" is actually a PHP file. The PHP file will execute when it is called at the bottom of the body, after the html file and all elements above it.

您可以通过CSS属性中的GET将数据发送到PHP文件...

You can send data to the PHP file via GET in the CSS property...

<!DOCTYPE html>
<html>
<head>
<title></title>
<style>
#runPHP
{ 
  background-image:url(script.php);
  display:none;
}
</style>
</head>
<body>

<div id="runPHP"></div>
</body>
</html>

这篇关于页面加载后运行PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆