JSONArray格式的数据,Ajax如何在前台解析?

beijibingdong 发布于 2016/08/05 08:51
阅读 3K+
收藏 0

 

这是后台return的数据样式,JSONArray对象。

[{"dataId":"20120116078","dataName":" 人事信息临时表"},{"dataId":"20151124136","dataName":" 调整津补贴"},{"dataId":"20151118134","dataName":" 离退人员调动"},{"dataId":"20130811132","dataName":" 更新标准"},{"dataId":"20150204134","dataName":" 调整基本工资标准"},{"dataId":"20150212136","dataName":" 调整基本工资标准"},{"dataId":"20150212136","dataName":" 增加离退休费"}]

 

=========================================

我在前台页面这样取

<script type="text/javascript">
  window.onload=function(){    
 //加载初始化数据   
   addItems(); 
 }; 
 //加载初始化数据 
function addItems() {
   var ls_url = "<%=request.getContextPath()%>/rs/rswh.do?method=toShow_YWtypeInfo";
         $.ajax({
             url: ls_url,
             type: "get",
             dataType: "json",
             contentType: "application/json",
             traditional: false,
             success: function (data) {
                     var optionstring = "";
                     for (var j = 0; j < data.length; j++) {
                         optionstring += "<option value=\"" + data[j].dataId + "\" >" + data[j].dataName + "</option>";
                     }
                     $("#service_type").html("<option value='请选择'>请选择...</option> "+optionstring);
                 },
             error: function(XMLHttpRequest, textStatus, errorThrown) { 
               alert(XMLHttpRequest.status); 
               alert(XMLHttpRequest.readyState);
               alert(textStatus);
              }
         });         
     };
</script>

 

 

但是会报错,弹出这三个XMLHttpRequest, textStatus, errorThrown,的值分别是200  4  parsererror

这是请求的信息

请帮我看看我这个问题出在哪里了?

加载中
0
螃蟹大叔
螃蟹大叔
你这个是直接放到request里面的:
if(method.equals("toShow_YWtypeInfo")){ // 获取业务类型种类
            request.setAttribute("data", this.toShow_YWtypeInfo(request));
        }



0
螃蟹大叔
螃蟹大叔
看一下你后台代码
0
beijibingdong
beijibingdong

引用来自“刘万杰”的评论

看一下你后台代码

package com.zhongway.action;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import cn.com.zhongway.base.pub.report.made.cCharControl;

import com.zhongway.business.multi.BackDataSearch;
import com.zhongway.database.cDataControlA;
import com.zhongway.pub.ControlExceptionPrint;


/**
 * 人事业务流程维护类
 */
public class RSWHAction extends Action {
    @SuppressWarnings("unchecked")
   
    // 展示查询结果
 public ActionForward execute(ActionMapping mapping, ActionForm form,
   HttpServletRequest request, HttpServletResponse response)
   throws Exception {
     String method = request.getParameter("method");
     String result = ""; // 处理结果
     if(method.equals("toShowInfo")){ // 查询信息
      //保存查询结果集
      request.setAttribute("list", this.toShowInfo(request));
     }
     if(method.equals("toShowInfo_my")){ // 查询信息
      request.setAttribute("list", this.toShowInfo(request));
     }
     
     ////////////////////////
     if(method.equals("toShow_YWtypeInfo")){ // 获取业务类型种类
      request.setAttribute("data", this.toShow_YWtypeInfo(request));
     }
     ////////////////////////////
     
     
        if(method.equals("doWorkFlow")){ // 删除业务
      result = this.doWorkFlow(request);
      }
      
        if(method.equals("stopWorkFlow")){ // 强制结单
      result = this.stopWorkFlow(request);
      }
      
        if(method.equals("delPersonInfo")){//删除人员信息
      result = this.delPersonInfo(request);
      }
      
        if(method.equals("delPersonInfo")){//删除人员信息
         result = this.delPersonInfo(request);
        }
        if(method.equals("clearData")){//清除垃圾数据
      result = this.clearData(request);
     }
        if(method.equals("backDataSearch")){//撤销流程查询
      result = this.backDataSearch(request);
     }
        if(method.equals("DoBackData")){//撤销流程
      result = this.DoBackData(request);
     }
       
     if(!result.equals("")){
      response.getWriter().print(result);
      response.getWriter().flush();
      response.getWriter().close();
      return null;
     }
     return response.isCommitted()?null:mapping.findForward(request.getParameter("method"));
    }
   
   
   
   
    @SuppressWarnings("unchecked")
 private List toShowInfo(HttpServletRequest request){
     ControlExceptionPrint controlExceptionPrint = ControlExceptionPrint.getInstance();
     String work_type  = ""; // 业务类型
     String queryWhere = ""; // 查询参数
     String service_type = "";//查询-业务类型参数
       service_type = request.getParameter("service_type");
//      request.getParameter("service_type");
      try{
       service_type =
        new String(service_type.getBytes("iso-8859-1"),"GBK");

      }catch(Exception e){
       e.printStackTrace();
      }

     
     if(null != request.getParameter("queryParam") &&
       !"".equals(request.getParameter("queryParam"))){
      queryWhere = " where ";
      //queryParam参数拆分为String类型数组
      String []param  = cCharControl.ISOtoGb2312(request.getParameter("queryParam").toString()).split("@");
      //拼接查询参数
      for (int i = 0; i < param.length; i++) {
    queryWhere += " "+(param[i].toString()).split("~")0+"  like '%"+(param[i].toString()).split("~")1+"%' and";
   }
      //去掉尾部and
//      queryWhere  =queryWhere.substring(0,queryWhere.length()-3);
      
      //拼接查询字段(业务类型)参数
      if(null != request.getParameter("service_type") &&
           !"".equals(request.getParameter("service_type"))){
       queryWhere +=" tr_name(TYPE_ID, 'type_id') || ' -> ' || type_id like '%"+service_type+"%'" ;
      }else{
       queryWhere +=" tr_name(TYPE_ID, 'type_id') || ' -> ' || type_id like '%'" ;
      }
      
      
     }
     cDataControlA cdata = new cDataControlA();
     List list = new ArrayList();
     
     if(null != request.getParameter("workType")){
      work_type = request.getParameter("workType");
      
     }else{
      return null;
     }
     String sql = "";
     if(work_type.equals("delPersonInfo")){ // 删除人员信息
      sql = "select * from (select pid,tr_org(org),name,idcard,tr_codename(GENDER),to_char(WORKDATE,'yyyy-mm-dd'),tr_codename(JOB),tr_codename(PERSONNELDEPT),BDSTATUS,tr_name(TYPE_ID,'type_id')||' -> '||type_id from tbl_info_baseinfor "+queryWhere+" ) where rownum<=15";
     }else{
      String method = request.getParameter("method");
      //判断是否为jWHRSInfoList_my.jsp页面请求
      if(method.equals("toShowInfo_my")){
       sql = "select * from (select pid,tr_org(org),name,idcard,BDSTATUS,tr_name(TYPE_ID,'type_id')||' -> '||type_id from tbl_info_baseinfor_temp "+queryWhere+" ) where rownum<=15";
      }else{
       //删除流程信息或者强制结单
          sql = "select * from (select pid,tr_org(org),name,idcard,tr_codename(GENDER),to_char(WORKDATE,'yyyy-mm-dd'),tr_codename(JOB),tr_codename(PERSONNELDEPT),BDSTATUS,tr_name(TYPE_ID,'type_id')||' -> '||type_id from tbl_info_baseinfor_temp "+queryWhere+" ) where rownum<=15";
      }
     }
     controlExceptionPrint.printToConsole("model_base", sql);
     list = cdata.FresultList(sql);
     return list;
    }
   
  //删除业务流程
    private String doWorkFlow(HttpServletRequest request){
     return this.Factory(request,"{call PRO_DELTEMP(?,?) }");
    }
   
    //删除人员信息
 private String delPersonInfo(HttpServletRequest request){
  return this.Factory(request,"{call pro_delPersoninfo(?,?) }");
 }
 
    //强制结单
 private String stopWorkFlow(HttpServletRequest request){
  return this.Factory(request,"{call pro_stopWorkFlow(?,?) }");
 }
 //重置流程
 private String resetWorkFlow(HttpServletRequest request){
   //return this.Factory(request,"{call pro_resetWorkFlow(?,?) }");
  return null;
 }
 //垃圾数据清理
 private String clearData(HttpServletRequest request){
  return this.Factory(request,"{call PRO_DELTEMP(?,?) }");
 }
 
 //撤销流程查询
 private String backDataSearch(HttpServletRequest request){
  List list = new ArrayList();
  list = this.backDataList(request);
  request.setAttribute("backDataSearch", list);
  return "";
 }
 //撤销流程
 private String DoBackData(HttpServletRequest request){
  return this.DoBack(request);
 }
 
 // 执行过程
 private String Factory(HttpServletRequest request,String pro_name){
  cDataControlA   cData = null;
        try {
            //获取数据库联接
          cData = new cDataControlA();
        } catch (Exception e) {
            e.printStackTrace();
        }
  String paramValue = "";//人员编码参数集合 以~分割
     if(null!=request.getParameter("paramValue")
       && !"".equals(request.getParameter("paramValue"))){
      try {
    paramValue = request.getParameter("paramValue");
    String []params = paramValue.split("~");
    String rybm[] = new String1;
     for (int i = 0; i < params.length; i++) {
     rybm0 = params[i];
     cData.calloutprocupdate(pro_name,rybm);
     if(cData.getDBStatus()<0){
        return "false";
     }
    }
   } catch (Exception e) {
    e.printStackTrace();
   }
     }else{
      return "false";
     }
     return "succ";
 }
 
 //查询撤销流程
 private List backDataList(HttpServletRequest request){
  BackDataSearch back_obj = new BackDataSearch();
  cDataControlA   cData =  new cDataControlA();
  List list = new ArrayList();
  String tbl_field = back_obj.fieldParam(request);
  String tbl_name  = back_obj.tblName(request);
  String tbl_where = back_obj.whereParam(request);
  String trfield = back_obj.TrNamefieldParam(request);
  String sql = "select t.*,rownum rn from (select "+trfield+" from (select "+tbl_field+" from "+tbl_name + " where "+tbl_where+") ) t";
  list = cData.FresultList(sql);
  return list;
 }
 //撤销流程
 private String DoBack(HttpServletRequest request){
  cDataControlA   cData =  new cDataControlA();
  String res = "false";
  String param = "";
  String user_code = (String)request.getSession(false).getAttribute("user_id");
  if(null != request.getParameter("rybm") &&
    !"".equals(request.getParameter("rybm"))){
   param = request.getParameter("rybm").toString().trim();
  }
  String sql = " delete from tbl_base_flow f where flowstep = ( select (flowstep+1) from tbl_base_flow " +
         " where sheetsn = f.sheetsn and personid='"+user_code+"' and status='02') and sheetsn in " +
         "(select max(sheetsn) from tbl_infoflow_baseinfor where pid in("+param+") group by sheetsn ) and status='00' ◎ "+
      " update tbl_base_flow f set status='00',dealtime=null where sheetsn in" +
      " (select max(sheetsn) from tbl_infoflow_baseinfor where pid in("+param+") group by sheetsn ) " +
      " and status='02' and dealperson='"+user_code+"' ";
  int num = cData.BatchSql(sql);
  if(num>0){
   res = "succ";
  }
  return res;
 }
 
 
/////////////////
 
  @SuppressWarnings("unchecked")
  private JSONArray toShow_YWtypeInfo(HttpServletRequest request){
      ControlExceptionPrint controlExceptionPrint = ControlExceptionPrint.getInstance();
 
      cDataControlA cdata = new cDataControlA();
      
    
      String sql = "";
    
           sql = "SELECT T.TYPE_ID , T.TYPE_NAME FROM tbl_info_type t";
           
           
             /* List list=cdata.FresultListField(sql);
              Map map = new HashMap();
           map.put("list", list);
              JSONArray json = JSONArray.fromObject(list);
           response.setCharacterEncoding("GBK");
           response.getWriter().print(json);
           return json;*/
           
//              List list = cdata.FresultList(sql);
//                 request.setAttribute("list", list);

           
           
      List list = new ArrayList();
      list = cdata.FresultList(sql);
      JSONArray data =
//        "{myjson:"+DataTableJson(list).toString()+"}";
        DataTableJson(list);
      
      
      
//      return DataTableJson(list).toString();
      return data;
//      return DataTableJson(list);
//                 return "succe";
  }
 
  public static JSONArray DataTableJson(List list)
     {
        // StringBuilder jsonBuilder = new StringBuilder();
   String data = null ;
         List datas = new ArrayList();
         List<ServiceType> listServiceType = new ArrayList<ServiceType>();
        
        
         for (int i = 0;i<list.size();i++) {
         datas.add(list.get(i));
          data = datas.get(i).toString();
          String dataId = data.substring(1, 12);
          String dataName = data.substring(14, data.length()-1);
          ServiceType serviceType = new ServiceType();
           serviceType.setDataId(dataId);
           serviceType.setDataName(dataName);
           listServiceType.add(serviceType);
         
  }
         JSONArray dataJson=  Tojson.JsonArray(listServiceType);
        
        
        return dataJson ;
     }


 
 
 
 
////////////////
 
}

0
beijibingdong
beijibingdong

引用来自“刘万杰”的评论

看一下你后台代码
package com.zhongway.action;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import cn.com.zhongway.base.pub.report.made.cCharControl;

import com.zhongway.business.multi.BackDataSearch;
import com.zhongway.database.cDataControlA;
import com.zhongway.pub.ControlExceptionPrint;


/**
 * 人事业务流程维护类
 */
public class RSWHAction extends Action {
    @SuppressWarnings("unchecked")
    
    // 展示查询结果
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
    	String method = request.getParameter("method");
    	String result = ""; // 处理结果
    	if(method.equals("toShowInfo")){ // 查询信息
    		//保存查询结果集
    		request.setAttribute("list", this.toShowInfo(request));
    	}
    	if(method.equals("toShowInfo_my")){ // 查询信息
    		request.setAttribute("list", this.toShowInfo(request));
    	}
    	
    	////////////////////////
    	if(method.equals("toShow_YWtypeInfo")){ // 获取业务类型种类
    		request.setAttribute("data", this.toShow_YWtypeInfo(request));
    	}
    	////////////////////////////
    	
    	
        if(method.equals("doWorkFlow")){ // 删除业务
    		result = this.doWorkFlow(request);
    	 }
       
        if(method.equals("stopWorkFlow")){ // 强制结单
    		result = this.stopWorkFlow(request);
    	 }
       
        if(method.equals("delPersonInfo")){//删除人员信息
    		result = this.delPersonInfo(request);
    	 }
       
        if(method.equals("delPersonInfo")){//删除人员信息
   		    result = this.delPersonInfo(request);
        }
        if(method.equals("clearData")){//清除垃圾数据
    		result = this.clearData(request);
    	}
        if(method.equals("backDataSearch")){//撤销流程查询
    		result = this.backDataSearch(request);
    	}
        if(method.equals("DoBackData")){//撤销流程
    		result = this.DoBackData(request);
    	}
        
    	if(!result.equals("")){
    		response.getWriter().print(result);
    		response.getWriter().flush();
    		response.getWriter().close();
    		return null;
    	}
    	return response.isCommitted()?null:mapping.findForward(request.getParameter("method"));
    }
    
    
    
    
    @SuppressWarnings("unchecked")
	private List toShowInfo(HttpServletRequest request){
    	ControlExceptionPrint controlExceptionPrint = ControlExceptionPrint.getInstance();
    	String work_type  = ""; // 业务类型
    	String queryWhere = ""; // 查询参数
    	String service_type = "";//查询-业务类型参数
    			service_type = request.getParameter("service_type");
//    		request.getParameter("service_type");
    		try{
    			service_type =
    				new String(service_type.getBytes("iso-8859-1"),"GBK");

    		}catch(Exception e){
    			e.printStackTrace();
    		}

    	
    	if(null != request.getParameter("queryParam") && 
    			!"".equals(request.getParameter("queryParam"))){
    		queryWhere = " where ";
    		//queryParam参数拆分为String类型数组
    		String []param  = cCharControl.ISOtoGb2312(request.getParameter("queryParam").toString()).split("@");
    		//拼接查询参数
    		for (int i = 0; i < param.length; i++) {
				queryWhere += " "+(param[i].toString()).split("~")0+"  like '%"+(param[i].toString()).split("~")1+"%' and";
			}
    		//去掉尾部and
//    		queryWhere  =queryWhere.substring(0,queryWhere.length()-3);
    		
    		//拼接查询字段(业务类型)参数
    		if(null != request.getParameter("service_type") && 
        			!"".equals(request.getParameter("service_type"))){
    			queryWhere +=" tr_name(TYPE_ID, 'type_id') || ' -> ' || type_id like '%"+service_type+"%'" ;
    		}else{
    			queryWhere +=" tr_name(TYPE_ID, 'type_id') || ' -> ' || type_id like '%'" ;
    		}
    		
    		
    	}
    	cDataControlA cdata = new cDataControlA();
    	List list = new ArrayList();
    	
    	if(null != request.getParameter("workType")){
    		work_type = request.getParameter("workType");
    		
    	}else{
    		return null;
    	}
    	String sql = "";
    	if(work_type.equals("delPersonInfo")){ // 删除人员信息
    		sql = "select * from (select pid,tr_org(org),name,idcard,tr_codename(GENDER),to_char(WORKDATE,'yyyy-mm-dd'),tr_codename(JOB),tr_codename(PERSONNELDEPT),BDSTATUS,tr_name(TYPE_ID,'type_id')||' -> '||type_id from tbl_info_baseinfor "+queryWhere+" ) where rownum<=15";
    	}else{ 
    		String method = request.getParameter("method");
    		//判断是否为jWHRSInfoList_my.jsp页面请求
    		if(method.equals("toShowInfo_my")){
    			sql = "select * from (select pid,tr_org(org),name,idcard,BDSTATUS,tr_name(TYPE_ID,'type_id')||' -> '||type_id from tbl_info_baseinfor_temp "+queryWhere+" ) where rownum<=15";
    		}else{
    			//删除流程信息或者强制结单
        		sql = "select * from (select pid,tr_org(org),name,idcard,tr_codename(GENDER),to_char(WORKDATE,'yyyy-mm-dd'),tr_codename(JOB),tr_codename(PERSONNELDEPT),BDSTATUS,tr_name(TYPE_ID,'type_id')||' -> '||type_id from tbl_info_baseinfor_temp "+queryWhere+" ) where rownum<=15";
    		}
    	}
    	controlExceptionPrint.printToConsole("model_base", sql);
    	list = cdata.FresultList(sql);
    	return list;
    }
    
  //删除业务流程
    private String doWorkFlow(HttpServletRequest request){
    	return this.Factory(request,"{call PRO_DELTEMP(?,?) }");
    }
    
    //删除人员信息
	private String delPersonInfo(HttpServletRequest request){
		return this.Factory(request,"{call pro_delPersoninfo(?,?) }");
	}
	
    //强制结单
	private String stopWorkFlow(HttpServletRequest request){
		return this.Factory(request,"{call pro_stopWorkFlow(?,?) }");
	}
	//重置流程
	private String resetWorkFlow(HttpServletRequest request){
			//return this.Factory(request,"{call pro_resetWorkFlow(?,?) }");
		return null;
	}
	//垃圾数据清理
	private String clearData(HttpServletRequest request){
		return this.Factory(request,"{call PRO_DELTEMP(?,?) }");
	}
	
	//撤销流程查询
	private String backDataSearch(HttpServletRequest request){
		List list = new ArrayList();
		list = this.backDataList(request);
		request.setAttribute("backDataSearch", list);
		return "";
	}
	//撤销流程
	private String DoBackData(HttpServletRequest request){
		return this.DoBack(request);
	}
	
	// 执行过程
	private String Factory(HttpServletRequest request,String pro_name){
		cDataControlA   cData = null;
        try {
            //获取数据库联接
       	  cData = new cDataControlA();
        } catch (Exception e) {
            e.printStackTrace();
        }
		String paramValue = "";//人员编码参数集合 以~分割
    	if(null!=request.getParameter("paramValue")
    			&& !"".equals(request.getParameter("paramValue"))){
    		try {
				paramValue = request.getParameter("paramValue");
				String []params = paramValue.split("~");
				String rybm[] = new String1;
				 for (int i = 0; i < params.length; i++) {
					rybm0 = params[i];
					cData.calloutprocupdate(pro_name,rybm);
					if(cData.getDBStatus()<0){
						  return "false";
					}
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
    	}else{
    		return "false";
    	}
    	return "succ";
	}
	
	//查询撤销流程
	private List backDataList(HttpServletRequest request){
		BackDataSearch back_obj = new BackDataSearch();
		cDataControlA   cData =  new cDataControlA();
		List list = new ArrayList();
		String tbl_field = back_obj.fieldParam(request);
		String tbl_name  = back_obj.tblName(request);
		String tbl_where = back_obj.whereParam(request);
		String trfield = back_obj.TrNamefieldParam(request);
		String sql = "select t.*,rownum rn from (select "+trfield+" from (select "+tbl_field+" from "+tbl_name + " where "+tbl_where+") ) t";
		list = cData.FresultList(sql);
		return list;
	}
	//撤销流程
	private String DoBack(HttpServletRequest request){
		cDataControlA   cData =  new cDataControlA();
		String res = "false";
		String param = "";
		String user_code = (String)request.getSession(false).getAttribute("user_id");
		if(null != request.getParameter("rybm") && 
				!"".equals(request.getParameter("rybm"))){
			param = request.getParameter("rybm").toString().trim();
		}
		String sql = " delete from tbl_base_flow f where flowstep = ( select (flowstep+1) from tbl_base_flow " +
				     " where sheetsn = f.sheetsn and personid='"+user_code+"' and status='02') and sheetsn in " +
				     "(select max(sheetsn) from tbl_infoflow_baseinfor where pid in("+param+") group by sheetsn ) and status='00' ◎ "+
					 " update tbl_base_flow f set status='00',dealtime=null where sheetsn in" +
					 " (select max(sheetsn) from tbl_infoflow_baseinfor where pid in("+param+") group by sheetsn ) " +
					 " and status='02' and dealperson='"+user_code+"' ";
		int num = cData.BatchSql(sql);
		if(num>0){
			res = "succ";
		}
		return res;
	}
	
	
/////////////////
	
	 @SuppressWarnings("unchecked")
		private JSONArray toShow_YWtypeInfo(HttpServletRequest request){
	    	ControlExceptionPrint controlExceptionPrint = ControlExceptionPrint.getInstance();
	
	    	cDataControlA cdata = new cDataControlA();
	    	
	    
	    	String sql = "";
	    
	        		sql = "SELECT T.TYPE_ID , T.TYPE_NAME FROM tbl_info_type t";
	        		
	        		
	            /*	List list=cdata.FresultListField(sql);
	            	Map map = new HashMap();
	        		map.put("list", list);
	            	JSONArray json = JSONArray.fromObject(list);
	        		response.setCharacterEncoding("GBK");
	        		response.getWriter().print(json);
	        		return json;*/
	        		
//	        		   List list = cdata.FresultList(sql);
//	        		      request.setAttribute("list", list);

	        		
	        		
	    	List list = new ArrayList();
	    	list = cdata.FresultList(sql);
	    	JSONArray data =
//	    			"{myjson:"+DataTableJson(list).toString()+"}";
	    			DataTableJson(list);
	    	
	    	
	    	
//	    	return DataTableJson(list).toString();
	    	return data;
//	    	return DataTableJson(list);
//	        		      return "succe";
	 }
	
	 public static JSONArray DataTableJson(List list)
     {
        // StringBuilder jsonBuilder = new StringBuilder();
		 String data = null ;
         List datas = new ArrayList();
         List<ServiceType> listServiceType = new ArrayList<ServiceType>();
         
         
         for (int i = 0;i<list.size();i++) {
        	datas.add(list.get(i));
        		data = datas.get(i).toString();
        		String dataId = data.substring(1, 12);
        		String dataName = data.substring(14, data.length()-1);
        		ServiceType serviceType = new ServiceType();
        		 serviceType.setDataId(dataId);
        		 serviceType.setDataName(dataName);
        		 listServiceType.add(serviceType);
        	 
		}
         JSONArray dataJson=  Tojson.JsonArray(listServiceType);
         
         
        return dataJson ;
     }


	
	
	
	
////////////////
 
}


0
螃蟹大叔
螃蟹大叔
你在后台加入以下以下代码,可能你返回的仅是字符串,所以前端报错:
response.setCharacterEncoding("UTF-8");
response.setContentType("application/json; charset=utf-8");



0
岁月轻狂k
岁月轻狂k
在ajax success方法里 先alert() 下。正常的话用$.each(data,function(idx,item){  } 遍历操作(我看你后台返回的就是json 格式)。如果是json字符串如 '[{"dataId":"20150212136","dataName":" 调整基本工资标准"},{"dataId":"20150212136","dataName":" 增加离退休费"}]' 需要先解析data 用var dataObj = eval("("+arr+")"); 解析在遍历
0
beijibingdong
beijibingdong

引用来自“岁月轻狂k”的评论

在ajax success方法里 先alert() 下。正常的话用$.each(data,function(idx,item){  } 遍历操作(我看你后台返回的就是json 格式)。如果是json字符串如 '[{"dataId":"20150212136","dataName":" 调整基本工资标准"},{"dataId":"20150212136","dataName":" 增加离退休费"}]' 需要先解析data 用var dataObj = eval("("+arr+")"); 解析在遍历

进不去,把 dataType: "json"这注掉才能进去,但是data是null

岁月轻狂k
岁月轻狂k
if(method.equals("toShow_YWtypeInfo")){ // 获取业务类型种类 request.setAttribute("data", this.toShow_YWtypeInfo(request)); } 这有问题,看你后台代码
岁月轻狂k
岁月轻狂k
那就时你后台返回的数据有问题呗。用火狐的RESTClient测试下
0
beijibingdong
beijibingdong

引用来自“刘万杰”的评论

你在后台加入以下以下代码,可能你返回的仅是字符串,所以前端报错:
response.setCharacterEncoding("UTF-8");
response.setContentType("application/json; charset=utf-8");



还是一样,data拿不到数据
0
liuleidefeng
liuleidefeng
你的返回类型有问题,看你的response 的Content-Type是 text/html,而你ajax请求已经注明返回结果是json,所以不会进入回调方法而直接报错。所以检查一下你的服务端,正确的json返是ContentType:application/json;
0
e
earthdog

1. Content-Type设置为application/json;

2. 返回的时候不要使用GBK,试着改用UTF-8试试;

3. 如果还不行,考虑不要直接返回JSON数组,在外面在包一个对象试试;

返回顶部
顶部