Ok, I figured it out from a different post. The result can either be handled within the success callback, or you can add an argument that is itself a callback function and apply the result of the ajax request to the callback.
function jsonServerResponse(operation, callback, JSOoptionalData) {
JSOoptionalData = (typeof JSOoptionalData == "undefined") ? 'defaultValue' : JSOoptionalData
jqxhr = $.ajax({
type: "POST",
contentType: "application/json",
url: "process.php",
data: "apicommand=" + operation + "&optionaldata" + JSON.stringify(JSOoptionalData),
dataType: "json",
success: function (json) {
if(typeof callback === 'function') callback.apply(this, [json]);
}
});
}
jsonServerResponse("get_something_from_server", function(returnedJSO){
console.log(returnedJSO.Result.Some_data);
}, "optional_data");
And gdoron, the line you have asked about makes the third argument optional. I hear it's good practice, if you are going to pass some data onto the server (but you dont know how many variables) to add an optional argument and just pass a js object, convert this to a JSON string, and decode it server-side.
Peace! :)