Por que não tenho retorno no Ajax? Ele passa pelo alert(em cima do for), mas nunca entra no FOR. Não estou utilizando nenhum framework.
Servlet:
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
try {
recuperarValores(request, response);
} catch (Exception ex) {
Logger.getLogger(GetValores.class.getName()).log(Level.SEVERE, null, ex);
}
}
private void recuperarValores(final HttpServletRequest request, final HttpServletResponse response)
throws IOException, Exception {
request.setCharacterEncoding("UTF-8");
//response.setCharacterEncoding("UTF-8");
response.setContentType("application/json");
PrintWriter out = response.getWriter();
JSONArray jsonArray = new JSONArray();
JSONObject responseObj = new JSONObject();
try{
Escala_DAO e = new Escala_DAO();
List<Escala> procedimentos = e.GetEscalaFunc(12998, "2018-01-01", "2018-01-03");
//JSONArray jsonArray = new JSONArray();
for (Escala obj : procedimentos) {
JSONObject js = new JSONObject();
js.put("jsRe", obj.getRe());
js.put("jsEntra",obj.getEntrada());
js.put("jsSai", obj.getSaida());
System.out.println("**********"+obj.getSaida());//aqui imprime normal
jsonArray.put(js);
}
responseObj.put("jsonArray", jsonArray);
out.print(responseObj);
//out.print(responseObj.toString());
//pw.print(responseObj.toString());
//out.flush();
} catch (JSONException e) {
}
}
JSP:
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript" src="js/timeline.js"></script>
<link rel="stylesheet" type="text/css" href="css/timeline.css">
<script type="text/javascript" src="//code.jquery.com/jquery-2.1.1.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
</head>
<body onload="drawVisualization();">
<script type="text/javascript">
var timeline;
//-----------------------------------------------------------------------
var queryObject = "";
var queryObjectLen = "";
var processed_temp = new Array();
var processed_tensao = new Array();
google.load("visualization", "1", {packages:["corechart"]});
google.setOnLoadCallback(drawVisualization);
//---------------------
$.ajax({
dataType:'json',
url : './GetValores',
type : 'POST',
success: function(data) {
queryObject = eval('(' + JSON.stringify(data) + ')');
queryObjectLen = queryObject.jsonArray.length;
},
error: function() {
alert("Ocorreu um erro na requisição ajax");
}
});
alert("em cima do for");
for(var i=0;i<queryObjectLen;i++){
var inicio = +new Date(queryObject.jsonArray[i].jsEntra);
var fim = +new Date(queryObject.jsonArray[i].jsSai);
var content = "Jovani";
alert("DENTRO DO FOR !!!!!!!!!!!!!!!");
//data.push([inicio,fim,"teste"]);
}