我使用javascript有这个OOP但结果数据是未定义的。也许有人可以帮我解决这个问题。
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
});
但是当我在下面尝试时它起作用:
$(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是:
[Object, Object, Object]
0: Object
Name: "Test1"
>_proto_: Object
1: Object
Name: "Test2"
>_proto_: Object
2: Object
Name: "Test3"
>_proto_: Object
length: 3