2017-01-28 49 views
1

我想從一個模式的數據打印用戶的ID。我做了一切,我在執行方法中得到ID我把該ID放入jsonArray並打印在控制檯上,但現在didn 「T獲取ID在阿賈克斯的結果。當我把裏面的警覺導致檢查我是否得到它還是不是拋出空data.here是我的代碼,我想從一個模式的數據庫打印用戶的ID

// AJAX

function printUCID() 
{ 
    //alert("hi"); 
    $.ajax({ 
     url : "registerclient", 

     contentType: "application/json", 
     cache : false, 
     success : function(result) { 

      alert(result[0]); 
      /*cid=result;*/ 
      } 
     }); 

} 

的代碼這裏是我的執行方法

public String execute() throws SQLException, ClassNotFoundException, IOException, JSONException { 
     //System.out.println(email); 
     RegisterDao RDAO = new RegisterDao(); 

     //System.out.println("country " + country); 
     String i = RegisterDao.save(this); 
     HttpServletResponse response = ServletActionContext.getResponse(); 
     PrintWriter out =response.getWriter(); 


     response.setContentType("application/json"); 
     response.setCharacterEncoding("utf-8"); 
     System.out.println("########"+i); 
     JSONObject jobj = new JSONObject(); 
     //jobj.put("result",i); 

     //String data = jobj.getString("result"); 
     //System.out.println("data"+data); 
     JSONArray jsonArray1 = new JSONArray(); 
     jsonArray1.put(i); 

     out.print(i); 
     System.out.println("jsonArray1"+jsonArray1); 

     if (i.length() > 0) { 



    } 

我得到out.print() 中的數據,但現在卡在這裏請幫助我。謝謝你

回答

0

從執行函數返回JSON數組。

+0

是啊..我從執行函數返回JSON數組,但仍然沒有得到它的結果ajax.if可能可以請你引導我做一些代碼。 – Patrick

+0

您可以從瀏覽器控制檯檢查結果對象並查看它包含的內容。在Chrome中,按Ctrl + Shift + j – MACMAN

+0

只需使用console.log(結果)並在瀏覽器中運行並檢查。 – MACMAN

相關問題