我的jquery的代码 
jQuery.ajax({  
                        type:"POST",  
                        url:"managerName",  
                      //  data:"systemkey="+selectValue,     // 传入的参数  
                        timeout: 10000,  
                        data:null,
                        dataType:"json",
                        
                        error : function(data) {
        alert(data.returnValue);
              },
                        
                        success:function(data){   
                alert("success");
                        setValue(data);  
                              } 
                    
                        }); 
   
}  后端action 的代码
public String managerName(){
response.setContentType("application/xml;charset=UTF-8");
        PrintWriter out = null;
try {
out = response.getWriter();
} catch (IOException e) {
e.printStackTrace();
}        try
        {
         String context=""; 
         List<ManagerPo> managerList = (List<ManagerPo>) this.service.getList(namespace+"getManager", null);
         for(ManagerPo manager : managerList ){
         context += manager.getManagerId()+":"+manager.getUserName()+",";
         }
         out.print(context);
        
           
        } finally
        {
            out.close();
        }
        
        return null;

}struts.xml文件
 <action name="managerName" class="registerAction" method="managerName"><!-- 向select中动态增加manager元素 -->
  </action><!-- -->是不是只要将返回值放入out 对象里就可以了?
但是jquery 执行了error : function(data)。
急!
  

解决方案 »

  1.   

    out.print(context);
    最后一句JSON格式不正确啊!!

    out.println("{returnValue:'" + context+ "'}");

      

  2.   

    net.sf.json.JSONObject jsonObj = new net.sf.json.JSONObject();
    net.sf.json.JSONArray jsonFormalArr = new net.sf.json.JSONArray();
    net.sf.json.JSONObject json = new net.sf.json.JSONObject();
    for()
    {
    json.put("content1", string1);
    json.put("content2", string2);
    json.put("content3", string3);
    json.put("content4", string4);
    ...
    jsonFormalArr.add(json);
    )
    jsonObj.put("formalInfo", jsonFormalArr);js
    var arr = data.formalInfo;
    for()
    {
    arr[i].content1;
    ....
    }
    这种方式绝对比你自己组织json格式清楚。
      

  3.   

    先搞清楚问题出在哪里。
    把那个链接不要用ajax请求,直接在浏览器里访问,看看返回什么结果,如果出错,那就是后台错误。如果页面返回的数据是你想要的,那么就是js处理错误。或者你用firebug看一下,看看请求的返回是什么。先搞清楚问题是出哪里了。
      

  4.   

    是后台错了
    This page contains the following errors:error on line 1 at column 1: Document is empty
    现在应该怎么办呢?是不是应该把字符串放在out对象里就可以了呢?