From all the answers I've been given, I've decided to use the object reference variable since I need .data to have the same name. However I'm not sure if I am using the variable correctly. I think I just need to do the following:
var myData = [];
$.ajax({
url: url,
dataType: "json",
cache: true,
success: function(data) {
$.each(data, function(i, item){
myData.push(item);
});
alert(myData);
Unfortunately its still not working correctly..
when I call the function onload i get the following output from the alert 10, " [object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]"
when I call the function a second time to get the next 10, I should have 20 objects in the file but instead I have only 10 "object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]"
ORIGINAL POST BELOW
Good day,
I am trying to add to some results from an Ajax call. Currently json gives me 10 items. When I call my loading function again, I want another 10 but I want to add it to the .data object so I get 20, then when it loads again 30, etc.
Is this possible to do?
The first call gives me back 10 results. It is:
$.ajax({
url: url,
dataType: "json",
cache: true,
success: function(data) {
}
});
I have set the following conditions for the second call.
if(data ===! null || data ===! 0 || data ===! ""){
$.each(data, function(i, item){
data.push(item.text);
});
The second call is not adding to data at all. I'm not sure what I should do. I have read from other questions that data is an object that holds an array. Why can't I just push 10 more to the array? Any help is appreciated.
Thank you