[英]AJAX - ok on server side, returns error on client side
I have a problem with an AJAX: In server side I get a result but in client side (javascript) it returns an error. 我有一个AJAX问题:在服务器端,我得到一个结果,但在客户端(javascript)中,它返回一个错误。
Server side: 服务器端:
@RequestMapping(value = "/nrConturi", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public List<Cerere> setNrConturi(@RequestParam(value = "jud", defaultValue = "") String jud,
@RequestParam(value = "aplic", defaultValue = "") String aplic,
@RequestParam(value = "oper", defaultValue = "") String oper) {
LOG.debug(">>>>> {}", jud);
LOG.debug(">>>>> {}", aplic);
LOG.debug(">>>>> {}", oper);
String numeJud = scoateNumeJudetDupaCod(jud);
List<Cerere> list = null;
String sql = "SELECT * FROM V_COM_DETALII_CERERE CER, COM_CERERE_APLICATIE APP, OPERATORECONOMIC OP, APLICATIE_PORTAL_EXTERN AP " +
"WHERE APP.FK_COM_CERERE_OP = CER.ID AND CER.COD_FISCAL = OP.CODFISCAL AND APP.FK_APLICATIE = AP.ID AND CER.STATUS=2";
if (jud != "" && aplic != "" && oper != "") {
sql += " AND CER.JUDET = '" + numeJud + "'";
sql += " AND APP.FK_APLICATIE = " + aplic;
sql += " AND OP.IDOPERATORECONOMIC = " + oper;
}
sql += " ORDER BY CER.ID";
list = jdbcTemplate.query(sql, CerereRowMapper.INSTANCE);
//I get here a size...xx list...
return list;
}
Client side: 客户端:
var filtramDupaAplicatie = $('#aplicatie_check').is(':checked');
var filtramDupaJudet = $('#judet_check').is(':checked');
var filtramDupaOperator = $('#opEc_check').is(':checked');
var aplicatie = "";
var judet = "";
var operator = "";
if (filtramDupaAplicatie)
aplicatie = $("#aplicatie").val();
if (filtramDupaJudet)
judet = $("#judet").val();
if (filtramDupaOperator)
operator = $("#operatorEconomic").val();
$.ajax({
url: contextPath + '/nrConturi',
data: {
jud: judet,
aplic: aplicatie,
oper: operator
},
encoding: "UTF-8",
contentType: "application/x-www-form-urlencoded; charset=UTF-8",
method: 'GET',
success: function (list) {
$('#nrConturi').val(list.length);
},
error: function(e){
displayError(JSON.stringify(e));
}
});
type Exception report 类型例外报告
message Request processing failed; 消息请求处理失败; nested exception is java.lang.IllegalStateException: getOutputStream() has already been called for this response 嵌套异常是java.lang.IllegalStateException:此响应已调用getOutputStream()
description The server encountered an internal error that prevented it from fulfilling this request. 描述服务器遇到内部错误,导致服务器无法满足此请求。
exception org.springframework.web.util.NestedServletException: Request processing failed; org.springframework.web.util.NestedServletException 异常 :请求处理失败; nested exception is java.lang.IllegalStateException: getOutputStream() has already been called for this response\\n........... 嵌套的异常是java.lang.IllegalStateException:此响应已调用getOutputStream()\\ n ...........
Ok, I solved the problem: 好的,我解决了这个问题:
@RequestMapping(value = "/nrConturi", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public List<Cerere> setNrConturi(@RequestParam(value = "jud", defaultValue = "") String jud,
@RequestParam(value = "aplic", defaultValue = "") String aplic,
@RequestParam(value = "oper", defaultValue = "") String oper) {
LOG.debug(">>>>> {}", jud);
LOG.debug(">>>>> {}", aplic);
LOG.debug(">>>>> {}", oper);
List<Cerere> list = cerereRepository.nrConturi(jud, aplic, oper);
return list;
}
and in cerereRepository: 并在cerereRepository中:
public List<Cerere> nrConturi(String jud, String aplic, String oper) {
List<Cerere> list = null;
String numeJud = scoateNumeJudetDupaCod(jud);
StringBuilder queryBuilder = new StringBuilder("select c from DetaliiCerere c");
if (!aplic.equals("")) {
queryBuilder.append(" join c.aplicatii a where a.id in (");
queryBuilder.append(aplic);
queryBuilder.append(")");
} else {
queryBuilder.append(" where");
}
if (!jud.equals("")) {
if (!aplic.equals(""))
queryBuilder = queryBuilder
.append(" and");
queryBuilder = queryBuilder
.append(" upper(c.judet)=upper('")
.append(numeJud)
.append("')");
}
if (!oper.equals("")) {
if (!aplic.equals("") || !jud.equals("")) {
queryBuilder = queryBuilder
.append(" and");
}
queryBuilder = queryBuilder
.append(" upper(c.codFiscal) like upper('%")
.append(oper)
.append("%')");
}
queryBuilder = queryBuilder
.append(" and c.status='Cerere aprobata'");
String jpQL = queryBuilder.toString();
LOG.debug("JPQL >> ... {}", jpQL);
Query query = entityManager.createQuery(jpQL);
list = query.getResultList();
return list;
}
and I've got the result in Javascript. 并且我已经用Javascript获得了结果。 Thx. 谢谢。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.