ajax异步请求定时刷新局部页面
<script>$(document).ready(function(){$.ajax({type:'GET',url:'http://localhost:8080/SS...
<script>
$(document).ready(function () {
$.ajax({
type: 'GET',
url:'http://localhost:8080/SSM/user/findRoom?region=1&&room=2',
dataType: 'json',
success:function (datas,status) {
console.log(datas);
console.log(status);
},
fail:function (err,status) {
console.log(err);
}
}).done(function(data) {
initDom(data);
$('body').find('.box:first').remove()
})
.fail(function() {
console.log('error');
}).always(function() {
console.log('complete');
});
})
function initDom(asyncData){
var username,address,address,content,join_time;
$.each(asyncData,function (index,item) {
console.log("index",index);
console.log("item",item);
var temp = $('.agileits-w3layouts').find('.team-grids:first')[0].outerHTML;
var box = $(temp);
var username = box.find('.username');
var id = box.find('.id');
var age = box.find('.age');
var sex = box.find('.sex');
var origin = box.find('.origin');
var region = box.find('.region');
var details = box.find('.details');
var photo = box.find('.photo');
username.html(item.username);
id.html(item.id
);
age.html(item.age);
sex.html(item.sex);
origin.html(item.origin);
region.html("软件部");
details.html(item.details);
var img = box.find('img');
img.attr('src',item.photo);
$('.agileits-w3layouts').append(box)
})
$('.agileits-w3layouts').find('.team-grids:first').remove()
}
请大神帮忙添加ajax定时任务 每隔一段时间就能调一次上面ajax请求 展开
$(document).ready(function () {
$.ajax({
type: 'GET',
url:'http://localhost:8080/SSM/user/findRoom?region=1&&room=2',
dataType: 'json',
success:function (datas,status) {
console.log(datas);
console.log(status);
},
fail:function (err,status) {
console.log(err);
}
}).done(function(data) {
initDom(data);
$('body').find('.box:first').remove()
})
.fail(function() {
console.log('error');
}).always(function() {
console.log('complete');
});
})
function initDom(asyncData){
var username,address,address,content,join_time;
$.each(asyncData,function (index,item) {
console.log("index",index);
console.log("item",item);
var temp = $('.agileits-w3layouts').find('.team-grids:first')[0].outerHTML;
var box = $(temp);
var username = box.find('.username');
var id = box.find('.id');
var age = box.find('.age');
var sex = box.find('.sex');
var origin = box.find('.origin');
var region = box.find('.region');
var details = box.find('.details');
var photo = box.find('.photo');
username.html(item.username);
id.html(item.id
);
age.html(item.age);
sex.html(item.sex);
origin.html(item.origin);
region.html("软件部");
details.html(item.details);
var img = box.find('img');
img.attr('src',item.photo);
$('.agileits-w3layouts').append(box)
})
$('.agileits-w3layouts').find('.team-grids:first').remove()
}
请大神帮忙添加ajax定时任务 每隔一段时间就能调一次上面ajax请求 展开
若以下回答无法解决问题,邀请你更新回答
2017-09-19
展开全部
不知道你的什么框架或者是原生js哈functionrefreshOnTime(){$.ajax({//配李弊衫置});//7秒后重复执行该函数setInterval('refreshOnTime',7000);}//开始执行自己refreshOnTime();//这样卜薯写的话,就会无限的重复执行自己,每次执行完后延哪腔迟自定义
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |