Im sure its something simple, but i cant seem to set variable data from within an AJAX request..
My servlet returns an array of numbers;
int[] array = {1,2,4,5,3,5,3,5};
response.setContentType("application/json");
response.setCharacterEncoding("UTF-8");
response.getWriter().write(new Gson().toJson(array));
The data is passed to jquery, where i am trying to store the json data as an jquery array;
var test2 = [];
$.post("servlet", { info: data},
function(data) {
alert(data); // this alerts what i want stored...
test2.push(3); // testing if i can add 3 to test FAILS
});
test2.push(9); //this works
test2.push(9); //this works
options.series[0].data = test2;
Why can’t i push a number onto test from with the ajax call?
The final result i want is to set options.series[0].data equal to the array of data returned by the servlet
How are you deciding that the push is “failing”? Keep in mind that the
3will be added LONG after the9s because your AJAX request is asynchronous.