I have several different forms that each return something different. I need to detect if it's a simple string (so i can put it in the error/status area) or if its javascript I do nothing and let it execute.
This is currently how I'm doing my checking, but I want to make sure this is 100% sturdy and reliable... I couldn't think of any other way.
The other option would be to always use JSON, but then I need a JSON shim, as well as somehow trying to serialize javascript into JSON.
$.ajax({
type: 'POST',
url: form.attr('action'),
data: form.serialize()
})
.done(function(data, textStatus, xhr) {
if (!xhr.getResponseHeader('Content-Type').match(/text\/javascript/i)) {
form.find('.status').text(data).removeClass().addClass('status status-done').slideDown(200);
} else {
// this is where i do nothing and let JS run
}
})
The following works, but I'm afraid there would be some edge case where it's not going to work (not sure what that might be, but it's important this section works 100%)