First, there is no return
statement inside the Load
function. In this case, it will return undefined
by default. There is nothing unexpected so far, but I guess you rather wanted to do things like that :
namespace.items.Load = function (arg1, arg2) {
return $.getJSON(
"/Object/Items",
{ "Arg1": arg1, "Arg2": arg2 },
function (Items) { return Items; }
);
}
That said, keep in mind that there is an Ajax call behind the scene which results in this kind of scenario :
- Load function is called.
- An Ajax request is sent to a remote server.
- Load function returns.
- An Ajax response is sent back.
function (Items) { return Items; }
is called.
What you were expecting to be returned by the Load
function is obviously not Items
. Thereby, you might use this kind of solution instead : https://stackoverflow.com/a/18793057/1636522.