当我们尝试使用它(不是$.getJSON()
)时,是否可以强制application/json
函数引发错误。似乎这个延迟只是将空对象返回到(或完成)。
我们怎样才能在then
处理程序中找到content-type
处理过的响应?
我知道当服务不可用时,服务器可以返回HTML而不是JSON。
答案 0 :(得分:1)
$.getJSON()
时, text/html
失败。见这个例子:
$.getJSON('http://httpbin.org/html')
.then(() => console.log('success'), () => console.log('error'))
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>