您可以尝试如下操作:
$.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,但似乎更可靠。



