[英]how do I sort this ajax php script
I have this script我有这个脚本
say index.html
说
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
<?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??加载 index.html 时它是空白的 10 秒然后它开始运行..我如何摆脱空白以及它如何在浏览器加载时立即显示?
Your setInterval()
call works as designed: It says "in 10 seconds and then every seconds, do this...."您的
setInterval()
调用按设计工作:它说“在 10 秒内,然后每隔一秒,执行此操作....”
Add a separate "load" call to do the initial filling:添加一个单独的“加载”调用来进行初始填充:
$(document).ready(function(){
$("#quote p").load("script.php"); // <--- Add this
setInterval(function(){
....
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.