Triggering a Javascript callback after a completed ajax call within an object
I'm trying to trigger an action after a Javascript object has been created via an AJAX call. My object looks something like this:

    function API(uid,accessToken){		
    		$.ajax("path/to/file", {
    			type: "POST",
    			data: { key: uid, key: accessToken },
    			dataType: "json",
    			success: function(jsonData) {
    				arrayname = jsonData[values]
    			}
    		});
    }

I tried to use JQuery's $.when function to do a callback after the object setup is complete (ie. the array is populated with the ajax response), which looked like this:

			
			$.when( API = new API(uid, accessToken) ).then(function() {
					...success function...
			});

...but the $.when function triggers with the arrayname values still undefined. From the function's standpoint the deferred object is resolved even though the object values have not yet been set. I've since tried a number of ways to make the API object become deferred based on the completing of the entire ajax call and the setting of the variables, but I'm a bit stuck on the best way to do this. 

Any pointers would be most appreciated! Thanks.
Triggering a Javascript callback after a completed ajax call within an object
===

I'm trying to trigger an action after a Javascript object has been created via an AJAX call. My object looks something like this:

    function API(uid,accessToken){		
    		$.ajax("path/to/file", {
    			type: "POST",
    			data: { key: uid, key: accessToken },
    			dataType: "json",
    			success: function(jsonData) {
    				arrayname = jsonData[values]
    			}
    		});
    }

I tried to use JQuery's $.when function to do a callback after the object setup is complete (ie. the array is populated with the ajax response), which looked like this:

			
			$.when( API = new API(uid, accessToken) ).then(function() {
					...success function...
			});

...but the $.when function triggers with the arrayname values still undefined. From the function's standpoint the deferred object is resolved even though the object values have not yet been set. I've since tried a number of ways to make the API object become deferred based on the completing of the entire ajax call and the setting of the variables, but I'm a bit stuck on the best way to do this. 

Any pointers would be most appreciated! Thanks.