我正在尝试使用 setInterval 每 5 秒刷新一次页面数据。我有一个简单的 html 表单,其中包含一个 ID 为“名称”的文本框。我也有一个提交按钮,它工作正常(代码也在下面),但我无法让页面自己发布。所有帮助表示赞赏。
<script type="text/javascript" src="/media/jquery-1.10.2.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
window.setInterval(function() {
AutoPost();
}, 5000);
});
function AutoPost() {
$.ajax({
// post the form values via AJAX…
var postdata = {name: $("#name").val()} ;
$.post('/submit', postdata, function(data) {
// and set the title with the result
$("#title").html(data['title']) ;
});
return false ;
});
});
}
$(function() {
// When the testform is submitted…
$("#testform").submit(function() {
// post the form values via AJAX…
var postdata = {name: $("#name").val()} ;
$.post('/submit', postdata, function(data) {
// and set the title with the result
$("#title").html(data['title']) ;
});
return false ;
});
});