I would like to concatenate a series of strings populated from an XHR response. So, I've chosen to do it like this:
$.post('/API',null,'json')
.done(function(response){
if (response.status === 'success') {
location = response.data.city + ', ' + response.data.state;
}
})
.fail(function(){
location = previousLocation;
})
.always(function(){
$("#location").text(location);
});
This feels clunky. Should I be more defensive in assuming a response from the API? Would this be more elegantly handled by some kind of templating function?