1

I have this script

say index.html

 <html>
    <head>
      <title>Ajax with jQuery Example</title>
      <script type="text/JavaScript" src="jquery.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){
      setInterval(function(){
        $("#quote p").load("script.php");
      }, 10000);
    });</script>
    <style type="text/css">
        #wrapper {
          width: 240px;
          height: 80px;
          margin: auto;
          padding: 10px;
          margin-top: 10px;
          border: 1px solid black;
          text-align: center;
        }
      </style>
    </head>
    <body>
      <div id="wrapper">
        <div id="quote"><p> </p></div>

      </div>
    </body>
    </html>

script.php

<?php

echo "Hello how are you";?>

when loading index.html it is blank for 10 seconds and then it start functioning..how do I get rid of blank and how it can show instantly when browser loads??

1
  • You do realise you're setting an interval of 10 seconds, hence why you see nothing for 10 seconds?? Commented May 26, 2011 at 8:58

1 Answer 1

4

Your setInterval() call works as designed: It says "in 10 seconds and then every seconds, do this...."

Add a separate "load" call to do the initial filling:

$(document).ready(function(){
  $("#quote p").load("script.php");  // <--- Add this

  setInterval(function(){
  ....
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.