I have a problem returning data back to the function I want it returned to. Code below:
function ioServer(request_data, callback)
{
$.ajax({
cach
I think maybe this is closer to what you are looking for...
function ioServer(request_data, callback)
{
$.ajax({
cache: false,
data: "request=" + request_data,
dataType: "json",
error: function(XMLHttpRequest, textStatus, errorThrown){},
success: function(response_data, textStatus){
processResponse(response_data, callback);
},
timeout: 5000,
type: "POST",
url: "/portal/index.php/async"
});
}
function processRequest(command, item, properties, callback)
{
var request = {};
request.command = command;
request.item = item;
request.properties = properties;
var toServer = JSON.stringify(request);
ioServer(toServer, callback);
}
//internal callback to handle response code
function processResponse(fromServer, callback)
{
if (fromServer.response == 1)
{
//call the callback with the id
callback(fromServer.id);
}
else
{
//You have to remember to call the callback no matter what
//or the caller won't know when it's complete
callback(null); //or some other "didn't get a valid response" value
}
}