You can try it like:
$.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
}
}
});
Basically it is also using indexOf but it seems more reliable.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…