2017-01-28 17 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

相关问题