鍍金池/ 問答/Java  HTML/ ajax 中readystate一直為1

ajax 中readystate一直為1

初學(xué)ajax,不明白為什么我在瀏覽器調(diào)試的過程中readystate一直沒有變化過,一直都是1.
這里是前端代碼:
function getMoreContent(){

var xmlHttp;
var content=document.getElementById("keyword");
if(content.value=="")
    {
    return;
    }
 xmlHttp=createXMLHttp();
 var url="search?keyword="+escape(content.value);
 xmlHttp.open("GET",url,true);
 xmlHttp.onreadystatechange=callback;
 xmlHttp.send();
}

function createXMLHttp(){

var xmlHttp;
if(window.XMLHttpRequest){
    xmlHttp=new XMLHttpRequest();
} 
if(window.ActiveXObject){
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    if(!xmlHttp){
        xmlHttp=new ActiveXObject("Msxml2.XMLHTTP")
    }
    
}
return xmlHttp;

}
function callback(){

if(xmlHttp.readyState==4)
    {
    if(xmlHttp.status==200)
        {
        //交互成功獲得數(shù)據(jù)
          var result=xmlHttp.responseText;
        //解析獲得的數(shù)據(jù)
        var json=eval("("+result+")");
        //獲得數(shù)據(jù)后展示到輸入框的下面
        alert(json);
        }
    }

}
function clearContent(){

var contentTableBody=document.getElementById("content_table_body");
var size=contentTableBody.childNodes.length;
for(var i=size-1;i>=0;i--)
    {
     contentTableBody.removeChild(contentTableBody.childNodes[i]);
    }

}

這里是后端Servlet的代碼:
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    // TODO Auto-generated method stub
    System.out.println("123");
   String keyword=request.getParameter("keyword");
   System.out.println(keyword);
   List<String> listData=getData(keyword);
   //返回JSON  測試輸出
   System.out.println("11");
   response.getWriter().write(JSONArray.fromObject(listData).toString());
   
   
   
   請問問題出在了哪里呢?
   

clipboard.png

回答
編輯回答
陌上花

http://blog.csdn.net/yoier/ar...

參考這個(gè)帖子

2018年2月13日 06:49
編輯回答
醉淸風(fēng)

你后端flush一下

2017年9月23日 15:50