I have an $.ajax call that includes both a success and error condition:
$('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');
}
});
});
Q: Should I also wrap this in a try/catch?
There is no need for try catch, as that adds to redundancy.
on jQuery’s side, they’ve done quite well on the error catching within their methods. As for your code, IMHO I don’t see the need.