开发者

how do I sort this ajax php script

I have this script

say inde开发者_StackOverflow中文版x.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??


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(){
  ....
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜