admin管理员组文章数量:1296400
I want to implement a ajax call to a page every 3 seconds.
It will either return 0
if false or a html snippet like <div>Content</div>
How should I proceed to place or remove that div on the page according to what ajax returns ?
I want to implement a ajax call to a page every 3 seconds.
It will either return 0
if false or a html snippet like <div>Content</div>
How should I proceed to place or remove that div on the page according to what ajax returns ?
Share Improve this question asked Apr 9, 2014 at 4:15 bockziorbockzior 1991 gold badge6 silver badges21 bronze badges 1- 2 what you have tried ? – Aamir Shahzad Commented Apr 9, 2014 at 4:17
2 Answers
Reset to default 3Use setInterval()
setInterval(ajaxCall, 3000);
function ajaxCall() {
$.ajax({url:url,
type:'html',
success:function(result){
if(result==0)
$('#content').hide();
else
$('#content').html(result).show();
}
});
}
<div id="content">Content</div>
One possible way:
html
<div id="one" style="display:none"></div>
<div id="two" style="display:block"></div>
Now in your success function set the appropriate div visible or hidden
ajax.request
({
// some code
success: function(response)
{
// here check the answer and show the div with id one
document.getElementById('one').style.display = 'block';
}
})
本文标签: javascriptAJAX to showhide divStack Overflow
版权声明:本文标题:javascript - AJAX to showhide div - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741638308a2389769.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论