jQuery ajax 我弄了个小实验

学习中,所以自己瞎做实验...

function ajaxSend_global(event, xhr, settings) 
{
    $("#info").append("<div><b>i am ajaxSend_global @ global ...</b><div>");
    $("#info").append("<div id='time'>结果搜索中...</div>");
    $("#info").append("</br>");
}

就是这个 结果搜索中... 是个静态提示..
怎么做成动态的?
我改成下面那个,就成了个死循环了,怎么让这个结果搜索中一直变?

function ajaxSend_global(event, xhr, settings) 
{
    $("#info").append("<div><b>i am ajaxSend_global @ global ...</b><div>");
    $("#info").append("<div id='time'></div>");
    $("#info").append("</br>");
    
    
    i=0;    while (xhr.status!=200)
    {
        $("#time").text( '结果搜索中...' +i );
        i++;
    }



慕雪6442864
浏览 640回答 1
1回答

梦里花落0921

<!DOCTYPE html><html><head>&nbsp; &nbsp; <meta charset="UTF-8">&nbsp; &nbsp; <title>Title</title></head><body><div id="info"></div><script src="jquery-2.1.4.min.js"></script><script>&nbsp; &nbsp; ajaxSend_global('shehe',4000,'heeh');&nbsp; &nbsp; function ajaxSend_global(event, xhr, settings) {&nbsp; &nbsp; &nbsp; &nbsp; $ ("#info").append ("<div><b>i am ajaxSend_global @ global ...</b><div>");&nbsp; &nbsp; &nbsp; &nbsp; $ ("#info").append ("<div id='time'></div>");&nbsp; &nbsp; &nbsp; &nbsp; $ ("#info").append ("</br>");&nbsp; &nbsp; &nbsp; &nbsp; var i=0,intervalId;&nbsp; &nbsp; &nbsp; &nbsp; if(xhr.status!=200){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; intervalId = setInterval(function () {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $("#time").text('结果搜索中...' + (++i));&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; },1000);&nbsp; &nbsp; &nbsp; &nbsp; }else {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; clearInterval(intervalId);&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }</script></body></html>
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript