A global ld object is used throughout my program. It’s contents can be entered manually, picked up from a server, or read from local storage. The writeload() function uses the ld object, and when the object is picked up from local storage, all is well. I had hoped that the JSON call would use the global storage ld, but it apparently doesn’t. Thus my question is: how to I get the JSON ld object to the global ld object. I’m pretty sure I could perform the writeload() function by duplicating its code inside the JSON call, but it’s long and I’d like to avoid that if possible. All suggestions are welcome as well as any thoughts on a better structure/way of doing things. Many thanks.
switch (oSource.from) {
case 'server':
$.getJSON('reports/' + oSource.filename,function(ld) {
writeload();
});
break;
case 'local':
ld=$.jStorage.get(oSource.filename);
writeload();
break;
}
how about this:
when you send a request to your URL (‘reports/’ + oSource.filename), it returns an object, and jQuery that you are using calls your function with this object as a parameter. the parameter is called new_ld inside the function invocation, so you just assign it to your global variable. In your original post, you had your function parameter named ‘ld’ and it effectively hid the global variable with the same name from the scope of the function.