Вы можете попробовать это как:
$.ajax({
type: "POST",
url: "your url goes here",
data: "data to be sent",
success: function(response, status, xhr){
var ct = xhr.getResponseHeader("content-type") || "";
if (ct.indexOf('html') > -1) {
//do something
}
if (ct.indexOf('json') > -1) {
// handle json here
}
}
});
В основном он также использует indexOf, но кажется более надежным.