Hi guys I am fairly new to AJAX.Right now I'm trying to develop a live graph by getting bunch of data continuously.However I am stuck on passing the data from servlet after calling the post function using ajax
JSP
<div id="chartContainer" style="height: 300px; width: 100%;"></div>
JS
function requestData() {
$.ajax({
url: "myURL",
type: "POST",
success: function() {
//Check if any notifications are returned - if so then display alert
alert("success");
},
error: function(){
//handle any error
alert("Error");
}
});
}
setInterval(function(){
requestData(),
updateChart()
}, updateInterval);
After calling AJAX, it will call the post function below.
protected void _doPostGraphData(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
ArrayList<String> arrayCurrency = new ArrayList<String>();
select.info info = new select.info();
ArrayList<select.Rates> rates = info.caseGetRates();
arrayCurrency.add(rates.get(0).getBid());
arrayCurrency.add(rates.get(0).getAsk());
JSONObject data = new JSONObject();
data.put("data",arrayCurrency);
response.setContentType("application/json; charset=UTF-8");
}
Right now I am stuck trying to pass my data back to JavaScript. Would love some guidance on how to get the data from post =).