After considering all the advice I've received, I have opted to utilize the object reference variable as I require .data to possess the same designation. However, I am uncertain if I am employing the variable correctly. It seems that all I need to do is:
var myData = [];
$.ajax({
url: url,
dataType: "json",
cache: true,
success: function(data) {
$.each(data, function(i, item){
myData.push(item);
});
alert(myData);
}
});
Regrettably, things are still not functioning correctly...
Upon invoking the function onload, the alert displays the following output: 10, "[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]"
Subsequently, when calling the function for a second time to retrieve the next set of 10, I should have 20 objects in total. Instead, I only receive 10: "[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]"
ORIGINAL POST BELOW
Greetings,
I am endeavoring to augment the results retrieved from an Ajax call. Initially, json returns 10 items. Upon invoking my loading function once more, I aspire to obtain an additional 10 and append them to the .data object, thus resulting in a collection of 20. Furthermore, with each subsequent load, I expect to gain increments of 10 (e.g., 30, 40, etc.)
Is this achievable?
The first call yields 10 results, outlined below:
$.ajax({
url: url,
dataType: "json",
cache: true,
success: function(data) {
}
});
I have established certain conditions for the second call.
if(data !== null || data !== 0 || data !== ""){
$.each(data, function(i, item){
data.push(item.text);
});
However, the second call fails to update the data array. I'm at a loss regarding the appropriate course of action. From what I understand, 'data' represents an object housing an array. Then why am I unable to simply add another 10 elements to the current array? Any guidance would be appreciated.
Thank you