I have this OOP using javascript but the resulted data is undefined. Maybe someone can help me to get through this.
var OOP = OOP || {
vars: {},
elems: {},
fn: {
loadData: function() {
$.post('URLOFPHP',
{} //This is blank because the URL Automatically loads all the resulted queries
).done(function(response){
var newData = $.parseJSON(response);
return newData;
//console.log(newData);
});
}
}
};
$(function() {
console.log(OOP.fn.loadData()); // This gives me undefined
});
But when I try below it works:
$(function() {
$.post('URLOFPHP',
{} //This is blank because the URL Automatically loads all the resulted queries
).done(function(response){
var newData = $.parseJSON(response);
//return newData;
console.log(newData);
});
});
Console.log of new Data is:
[Object, Object, Object]
0: Object
Name: "Test1"
>_proto_: Object
1: Object
Name: "Test2"
>_proto_: Object
2: Object
Name: "Test3"
>_proto_: Object
length: 3