Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 25

Thread: Body onload

  1. #1
    Regular Coder
    Join Date
    Dec 2010
    Location
    Kent, UK
    Posts
    573
    Thanks
    23
    Thanked 10 Times in 10 Posts

    Body onload

    hi guys, how can i get this code to load on body onload? without fading in and out?

    Code:
    <html>
    <head>
    <!-- For ease i'm just using a JQuery version hosted by JQuery- you can download any version and link to it locally -->
    <script src="http://code.jquery.com/jquery-latest.js"></script>
    <script>
     $(document).ready(function() {
     	 $("#responsecontainer").load("response.php");
       var refreshId = setInterval(function() {
          $("#responsecontainer").load('response.php?randval='+ Math.random());
       }, 9000);
       $.ajaxSetup({ cache: false });
    });
    </script>
    </head>
    <body>
     
    <div id="responsecontainer">
    </div>
    </body>
    Thanks
    http://360-tactics.co.uk/forum/index.php

    Crime-Wave

    please post your code wrapped in tags
    please post your PHP wrapped in tags

  • #2
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,396
    Thanks
    12
    Thanked 569 Times in 562 Posts
    There is no "fading in or out" in this code ...

  • #3
    Regular Coder
    Join Date
    Dec 2010
    Location
    Kent, UK
    Posts
    573
    Thanks
    23
    Thanked 10 Times in 10 Posts
    sorry i realised that after i posted, i just need to know how to get it to load the page on page load, as its not loading hte page at all :S
    http://360-tactics.co.uk/forum/index.php

    Crime-Wave

    please post your code wrapped in tags
    please post your PHP wrapped in tags

  • #4
    New Coder
    Join Date
    Dec 2011
    Location
    Earth if you want to know
    Posts
    27
    Thanks
    0
    Thanked 3 Times in 3 Posts
    Quote Originally Posted by Dan13071992 View Post
    sorry i realised that after i posted, i just need to know how to get it to load the page on page load, as its not loading hte page at all :S
    Hi there,

    [Please tell me if I misunderstand your question]

    I am not really sure what are your problems, the page should be rendered completely before the code can be executed using the .ready() syntax:

    Code:
    $(document).ready(function() {
        //You code here WILL be executed when the page is completely rendered
    });
    However, if you want the page to load completely, for all elements not only source code (such as images, flash...), use $(window) instead of $(document):

    Code:
    $(window).ready(function() {
        //You code here WILL be executed when the page is completely loaded, including images, flash...
    });
    Tim_

  • #5
    Regular Coder
    Join Date
    Dec 2010
    Location
    Kent, UK
    Posts
    573
    Thanks
    23
    Thanked 10 Times in 10 Posts
    i know have this

    Code:
    <script src="http://code.jquery.com/jquery-latest.js"></script>
    <script>
     $(window).ready(function() {
     	 $("#responsecontainer").load("inc-mess-jail.php");
       var refreshId = setInterval(function() {
          $("#responsecontainer").load('inc-mess-jail.php?randval='+ Math.random());
       }, 9000);
       $.ajaxSetup({ cache: false });
    });
    </script>
    
    <div id="responsecontainer">
    </div>
    thats not the full html as the div is inside html ect but alot of it.

    and in the inc-mess-jail.php file i have this:

    PHP Code:
    <?php
    include('../includes/db_connect.php');
    include(
    '../includes/inc-logincheck.php');
    include(
    '../includes/inc-functions.php');
    include(
    '../includes/inc-userfunctions.php');

    $intUserID=$_SESSION['uID'];
    $fetch=$user;


    $newMail mysql_query("SELECT * FROM `inbox` WHERE `to`='$fetch->username' AND `read`='0'");
    $newMail_rows mysql_num_rows($newMail);
    $inJail mysql_query("SELECT * FROM `jail` WHERE `location`='$fetchlocation->country'");
    $inJail_rows mysql_num_rows($inJail);

    $mailMessage '<a href="../inbox.php"><img align="left" src="../images/icons/'.($newMail_rows=='no' 'new').'Mail.gif" border="0" width="45" height="45"></a>';

    $jailIcon '<a href="../jail.php"><img align="left" src="../images/icons/'.($inJail_rows>='in' 'empty').'Jail.gif" border="0" width="45" height="45"></a>';

    ?>

    <tr>
      <td colspan="2" align="center">
      
      <table border="0" cellspacing="0" cellpadding="0" width="75%">
      <tr>
      <td width="50%" align="center" valign="center">
          <div id=messages><?php echo $mailMessage?></div>
      </td>

      <td width="50%" align="center" valign="center">
          <div id=jail><?php echo $jailIcon?></div>
      </td>
      </tr>
      </table>

      <span id="errorMsg"></span>  
      
      </td>
      </tr>
    however its not loading the div at all, and not even sjhowing an error message :s
    http://360-tactics.co.uk/forum/index.php

    Crime-Wave

    please post your code wrapped in tags
    please post your PHP wrapped in tags

  • #6
    New Coder
    Join Date
    Dec 2011
    Location
    Earth if you want to know
    Posts
    27
    Thanks
    0
    Thanked 3 Times in 3 Posts
    Quote Originally Posted by Dan13071992 View Post
    however its not loading the div at all, and not even sjhowing an error message :s
    Hi Dan,

    There could be various ways the errors take place, I suggest first of all, test the page inc-mess-jail.php alone first. Make sure that it will display what you expected, because whatever you saw there, will be exactly what you get using $.load(). If the problem is not from the PHP file, then we will have to mess with the JS file.

    Tim_

  • #7
    Regular Coder
    Join Date
    Dec 2010
    Location
    Kent, UK
    Posts
    573
    Thanks
    23
    Thanked 10 Times in 10 Posts
    hi tim, i have tested the inc-mess-jail.php file and it all works fine just the javascript/jquery thats not loading for some strange reason, im no good at javascript, or jquery and this is my first real attempt at it
    http://360-tactics.co.uk/forum/index.php

    Crime-Wave

    please post your code wrapped in tags
    please post your PHP wrapped in tags

  • #8
    New Coder
    Join Date
    Dec 2011
    Location
    Earth if you want to know
    Posts
    27
    Thanks
    0
    Thanked 3 Times in 3 Posts
    Quote Originally Posted by Dan13071992 View Post
    hi tim, i have tested the inc-mess-jail.php file and it all works fine just the javascript/jquery thats not loading for some strange reason, im no good at javascript, or jquery and this is my first real attempt at it
    Cool, so now we will have to work on the JS file.

    Replace your:

    Code:
    $("#responsecontainer").load("inc-mess-jail.php");
    By:

    Code:
    $("#responsecontainer").load("inc-mess-jail.php", function(response, status, xhr) {
        if (status == "error") {
            alert("Error: " + xhr.status + " " + xhr.statusText);
        }
    });
    And tell me what you got.

    Tim_

  • #9
    Regular Coder
    Join Date
    Dec 2010
    Location
    Kent, UK
    Posts
    573
    Thanks
    23
    Thanked 10 Times in 10 Posts
    im getting error 404 not found, my inc-footer.php page, which this javascript is being used in is in the includes folder, along ith inc-mess-jail.php could it be that i need to write includes/inc-mess-jail.php instead of inc-mess-jail.php ??
    http://360-tactics.co.uk/forum/index.php

    Crime-Wave

    please post your code wrapped in tags
    please post your PHP wrapped in tags

  • #10
    New Coder
    Join Date
    Dec 2011
    Location
    Earth if you want to know
    Posts
    27
    Thanks
    0
    Thanked 3 Times in 3 Posts
    Quote Originally Posted by Dan13071992 View Post
    im getting error 404 not found, my inc-footer.php page, which this javascript is being used in is in the includes folder, along ith inc-mess-jail.php could it be that i need to write includes/inc-mess-jail.php instead of inc-mess-jail.php ??
    The 404 Error Not found indicates your "inc-mess-jail.php" could not be found. Make sure that you have the correct path, or at least try the absolute path. You can also post here your folder structure, maybe I can help.

    The 404 Error alerted is not for the include() file in PHP. Because first, you run the inc-mess-jail.php alone and it works. If something is wrong, inc-mess-jail.php will display a message say that it "could not be found something blah blah blah", and you will receive exactly ("could not be found something blah blah blah") the same message when you use Ajax. Remember, whatever you see in the PHP file will be exactly what the browser receives after ajaxing.

    Tim_

  • #11
    Regular Coder
    Join Date
    Dec 2010
    Location
    Kent, UK
    Posts
    573
    Thanks
    23
    Thanked 10 Times in 10 Posts
    ok, i got it working, however now its showing above my javascript clock :s its ment to be displayed under it :s



    the div is positioned below the clock in the html :s so i dont know why its coming up above it :S
    http://360-tactics.co.uk/forum/index.php

    Crime-Wave

    please post your code wrapped in tags
    please post your PHP wrapped in tags

  • #12
    New Coder
    Join Date
    Dec 2011
    Location
    Earth if you want to know
    Posts
    27
    Thanks
    0
    Thanked 3 Times in 3 Posts
    Quote Originally Posted by Dan13071992 View Post
    ok, i got it working, however now its showing above my javascript clock :s its ment to be displayed under it :s



    the div is positioned below the clock in the html :s so i dont know why its coming up above it :S
    Do you have a live demo or can you upload your code? It's hard to tell about CSS just by gathering information. Just in case you don't have your code available, try to use Firebug or Google developer Tools to inspect your elements, your clock... and make sure the HTML code is as expected.

    Tim_

  • #13
    Regular Coder
    Join Date
    Dec 2010
    Location
    Kent, UK
    Posts
    573
    Thanks
    23
    Thanked 10 Times in 10 Posts
    that little block in the picture is diplayed like so:

    Code:
      <table border="0" width="120" cellspacing="0" cellpadding="0" class="cat">
      <tr>
      <td class="menu_header" width="120" height="15"><span class="menu_text">&nbsp;<img src="/game/site/site/bullet.gif"> <b>INFORMATION</b></span></td>
      </tr>
      <td>
      <img src="/game/site/site/table_top.gif"><br>
      
      <table border="0" cellspacing="0" cellpadding="0" width="100%" class="cat">
      <tr>
    
      <td colspan="2" align="center"><?php echo date('l'); ?><br /><span id="clock">&nbsp;</span></td>
      </tr>
      <tr>
      <td colspan="2" align="center"><div id="1"><?php echo "<a href='trainstation.php'>$fetchlocatfooterion->country</a>"; ?></div></td>
      </tr>
     
     
     
     
     
     <center>
    
    <div id="responsecontainer">
    </div>
    
     
    </center>
     
     
     
     
     
    
      </table>
    
      
      </td>
      </tr>
      
         
      
      </table>
    the javascript you already know to that part.

    below is the inc-mess-jail.php file:

    PHP Code:

    <?php
    include('../includes/db_connect.php');
    include(
    '../includes/inc-logincheck.php');
    include(
    '../includes/inc-functions.php');
    include(
    '../includes/inc-userfunctions.php');

    $intUserID=$_SESSION['uID'];
    $fetch=$user;


    $newMail mysql_query("SELECT * FROM `inbox` WHERE `to`='$fetch->username' AND `read`='0'");
    $newMail_rows mysql_num_rows($newMail);
    $inJail mysql_query("SELECT * FROM `jail` WHERE `location`='$fetchlocation->country'");
    $inJail_rows mysql_num_rows($inJail);

    $mailMessage '<a href="../inbox.php"><img align="left" src="../images/icons/'.($newMail_rows=='no' 'new').'Mail.gif" border="0" width="45" height="45"></a>';

    $jailIcon '<a href="../jail.php"><img align="left" src="../images/icons/'.($inJail_rows>='in' 'empty').'Jail.gif" border="0" width="45" height="45"></a>';

    ?>
    <link rel=stylesheet href=includes/screen.css type=text/css>
    <tr>
     <td colspan="2" align="center">
      
      <table border="0" cellspacing="0" cellpadding="0" width="75%">
      <tr>
      
      <td width="50%" valign="center">
          <?php echo $mailMessage?>
      </td>

      <td width="50%" valign="center">
          <?php echo $jailIcon?>
      </td>
      
       </tr>
      </table>
      
      </td>
      </tr>
    http://360-tactics.co.uk/forum/index.php

    Crime-Wave

    please post your code wrapped in tags
    please post your PHP wrapped in tags

  • #14
    New Coder
    Join Date
    Dec 2011
    Location
    Earth if you want to know
    Posts
    27
    Thanks
    0
    Thanked 3 Times in 3 Posts
    Do you have any CSS for #responseconainer?

    Try this: replace:

    Code:
     <center>
    
    <div id="responsecontainer">
    </div>
    
     
    </center>
    By:

    Code:
    <tr>
        <td colspan="2">
            <div id="responsecontainer" align="center"></div>
        </td>
    </tr>
    The above code simply add 1 more rows to the existed table, so it can make sure that the <div> always stay under all other above table rows.

    Tim_

  • #15
    Regular Coder
    Join Date
    Dec 2010
    Location
    Kent, UK
    Posts
    573
    Thanks
    23
    Thanked 10 Times in 10 Posts
    that worked a treat thanks it had been bugging me lol. thanks for all of your help, i have other javascript projects to do, such as integrating php into javascript to creat a forum using iframes that load the pages, from the left iframe into the right hand iframe, i have all the javascript codes and php codes, and as you can tell im no good at javascript, so i needed some help intergrating them :s.

    thanks for all your help on this topic. it was a big help, however is there a way to create a random javascipt pop up randomly after the user has gone to a different page say for example, the pop up will display a code that i set, and there is a random number of clicks between say 30 and 50, in the random number between 30 and 50 it creates the pop up to display the code, is that possible?

    thanks again.
    http://360-tactics.co.uk/forum/index.php

    Crime-Wave

    please post your code wrapped in tags
    please post your PHP wrapped in tags


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •