I have the function below that makes a request every second to the MySQL database and updates a DIV on the page. But after more or less 100 requests the "I ACHIEVE" database blocks and returns "An error occurred in the ajax request". What could it be?
ajax function:
<script type="text/javascript">
function UpdateValues() {
$(function() {
$.ajax({
data: {
'option': "telaValues"
},
url: './GetValores',
type: 'POST',
success: function(data) {
queryObject = eval('(' + JSON.stringify(data) + ')');
queryObjectLen = queryObject.jsonArray.length;
var varTensao = queryObject.jsonArray[0].jsonTensao;
var varCorrente = queryObject.jsonArray[0].jsonCorrente;
//alert(per);
document.getElementById("tensaoH1").innerHTML = "Tensão: "+varTensao+" V";
document.getElementById("correnteH2").innerHTML ="Corrente: "+varCorrente+" A";
},
error: function(xhr, status, error) {
alert("Error! " + xhr.error);
alert("Ocorreu um erro na requisição ajax");
}
});
});
}
</script>
<script type="text/javascript">
$(document).ready(function(){
setInterval(UpdateValues, 1000);
});
</script>
SERVLET:
.
.
else if(op.equals("telaValues")){
try {
JSONArray jsonArray = new JSONArray();
JSONObject responseObj = new JSONObject();
ResultSet rs = null;
rs = null;
request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("UTF-8");
response.setContentType("application/json");
PrintWriter out = response.getWriter();
//JSONObject responseObj = new JSONObject();
rs = new GrandezasDAO().rs("SELECT tensao,corrente from consumo1 order by id desc limit 1");// where mes_ref BETWEEN '"+firstDate+"' AND '"+secondDate+"");
//JSONArray jsonArray = new JSONArray();
//JSONObject responseObj = new JSONObject();
while(rs.next()){
JSONObject js = new JSONObject();
js.put("jsonTensao", rs.getInt("tensao"));
//js.put("temp", rs.getInt("temperatura"));
js.put("jsonCorrente", rs.getDouble("corrente"));
jsonArray.put(js);
}
responseObj.put("jsonArray", jsonArray);
out.print(responseObj);
//out.flush();
} catch (JSONException e) {
e.printStackTrace();
}
}
.
.
ERROR RETURN: (after 100 MySQL queries)
Error! function() {
if (u) {
var t = u.length;
(function i(t) {
b.each(t, function(t, n) {
var r = b.type(n);
"function" === r ? e.unique && p.has(n) || u.push(n) : n && n.length && "string" !== r && i(n)
})
})(arguments), n ? o = u.length : r && (s = t, c(r))
}
return this
}
Status Alert RETURN:
200