I do have a ajax code will work on a click of button. but I need it should automatically load function in between every 10 seconds. how can I rewrite below code??
<html>
<head>
<title>Ajax with jQuery Example</title>
<script type="text/JavaScript" src="jquery.js"></script>
<script type="text/JavaScript">
$(document).ready(fu开发者_如何学Pythonnction(){
$("#generate").click(function(){
$("#quote p").load("script.php");
});
});
</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>
<input type="submit" id="generate" value="Generate!">
</div>
</body>
</html>
$(document).ready(function(){
setInterval(function(){
$("#quote p").load("script.php");
}, 10000);
});
This will call $("#quote p").load("script.php")
(or more accurately, the anonymous function that contains this call) every 10 seconds (the second argument to setInterval
is specified in milliseconds).
You should be able to do this:
setInterval(function () {
$("#quote p").load("script.php");
}, 10000);
Which will load script.php every 10 seconds into $('#quote p')
.
精彩评论