I need to return multiple values from a ColdFusion function in an ajax callback function. Here's what I've got:
$('input[name="StateName"]').live('change', function() {
var StateID = $(this).parents('tr').attr('id');
var StateName = $(this).val();
$.ajax({
url: 'Remote/State.cfc'
,type: "POST"
,data: {
'method': 'UpdateStateName'
,'StateID': StateID
,'StateName': StateName
}
,success: function(result){
if (isNaN(result)) {
$('#msg').text(result).addClass('err');
} else {
$('#' + result + ' input[name="StateName"]').addClass('changed');
};
}
,error: function(msg){
$('#msg').text('Connection error').addClass('err');
}
});
});
If I trap a database error, then the success callback is fired, and the result is Not a Number (It is in fact, the text of the error message). I need the function to also pass back other values. One might be the primary key of the row that caused the error. Another might be the old StateName, so that I can refresh the old value on the screen so that the client will know absolutely for sure that their change did not take effect.
I guess I'm breaking the rule of atomicity here and need to fix that, because I'm using result as both the primary key of the row that was updated, or it's the error message if the update fails. I need to return both the primary key and the error message.