Its most likely, that you check the pageviews
array at the wrong spot. Liky any Ajax operation, .get()
works asynchronously by default, which means you can't just check that array after the .get()
call and expect the data was already updated.
Infact, its not, because it takes a while for the browser and your network to complete the data transfer. If you immediately check your array, after your .push()
call, I promise the array was updated as expected.
$.get( /* ... */ );
console.log( pageviews ); // wrong result, the array was not even touched at this point
You might find jQuerys implicit promise objects helpful, you might use it like
$.get( /* ... */ ).done(function( res ) {
pageviews.push([2, res.value]);
console.log(pageviews);
});
That is pretty much the exact same like you already do, but its syntax is probably in a more convenient fashion. The "done()" thing should make it pretty much clear.
Of course, you can also mixup those things (for whatever reason), like
$.get("http://bla..bla", function(res){
pageviews.push([2, res.value]);
}, "json").done(function() {
console.log( pageviews );
});