weixin_33690367 2014-04-09 04:15 采纳率: 0%
浏览 182

AJAX显示/隐藏div

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 ?

  • 写回答

2条回答 默认 最新

  • ℡Wang Yan 2014-04-09 04:21
    关注

    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';
        }
    })
    
    评论

报告相同问题?