Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9222105
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T03:44:08+00:00 2026-06-18T03:44:08+00:00

I have a lot of server code (PHP) going on in my first page

  • 0

I have a lot of server code (PHP) going on in my first page of the Facebook app.
I wan’t the users to see a loading animation while waiting for the page.

I’ve seen many examples here of how to preload a page (using ajax or simply jQuery) but this is different, as I said, the page itself is generated on the server, and while that goes on, the user only sees a white blank page.

I tried to wrap my main page with another php page:

<?php
include_once 'functions.php';
session_start();
$_SESSION['fb'] = new fb();

function phponload(){
    echo
        '<script>
            $(function(){
                $("#mwrapper").load("main.php");
            });
        </script>';
}
?>
<html>
<head>
    <script type="text/javascript">
        function delayer(){
        document.write("<?php phponload();?>");
        }
    </script>
    <link href='styles/default.css' rel='stylesheet' type='text/css' />
        <img class='mainload' src='images/loading.gif'></img>
    <script src='//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js'></script>
    <link rel='stylesheet' type='text/css' href='plugins/clock/clock.css' />
</head>

<body onload='setTimeout("delayer()",1000);'>
    <div id='mwrapper'>

    </div>
</body>

</html>

now the main php page (main.php) has something like:

<!DOCTYPE html>
<html xmlns:fb="http://ogp.me/ns/fb#">
<meta name="google-site-verification"         content="Hyqgg60NTPNA7Q9Z5y9TtezUmwhiEomwZLJDt43Ki2g" />
<!--<img class='mainload' src='images/loading.gif'></img>-->
<?php
include_once 'functions.php';
include 'res/views/getTables.php';
define('TXT_QUESTIONS_NUM', 43);
session_start();
{... more PHP code ... }
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.9.2/jquery-ui.min.js">  </script>
    <script src='scripts/menuItems.js'></script>
    <script src='scripts/main.js'></script>
    <link href='styles/jquery.ui.smooth.theme.css' rel='stylesheet' type='text/css'/>
    <script type="text/javascript" src="plugins/clock/clock.js"></script>
    <link rel="icon" href="images/favicon.ico">
</head>

<div class='container' id='main'>
...
</div>
</body>
</html>

Right now, all the code does is loop the GIF – but does not load main.php 🙁
Thank you!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T03:44:10+00:00Added an answer on June 18, 2026 at 3:44 am

    Is there any error on the Chrome/Firebug console?

    I don’t understand why you generate the loader JS code in the PHP function (you could put it directly in HTML), but by doing so you are putting a multiline block between the quotes on document.write function, which causes an error.

    However, I think the issue is that the browser is interpreting the inserted </script> as the end of the HTML tag, so what’s after (the end of the document.write call and the delayer function) are treated as HTML and not as Javascript.

    EDIT: Complementing the answer, here’s the code I’d use to load another page:

    function delayer(){
        $("#mwrapper").load("main.php", function(){
            $('.mainload').remove();
        });
    }
    

    Didn’t need any PHP generation. Also, the second argument to the load function is a callback called when the load is finish, in this case I used to remove the loading GIF.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have lot of code in my Tornado app which looks like this: @tornado.web.asynchronous
I have a page that has a lot going on, and when it finishes
I have a server that communicates to a lot of devices (>1000). Each connection
I have a CouchDB (1.1.1) server running that contains a lot of documents in
A have a database on MS-SQL Server 2008 that is growing a lot, year
Lately we been having a lot of problems with our mysql server i have
I have a wordpress website, recently I saw too much slow loading index page.
I have a problem with my PHP / SQL code. I have tried a
I have an android app, that connectos to the remote database with PHP+json but
I don't have a lot of experience with PHP - I used a form

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.