javascript - Should jQuery $.getJSON() method fail when the response is text/html? -
is possible force $.getjson()
function raise error when try html (not application/json
). seems deferred returns empty object (or done).
how can find in then
handler content-type
processed in response? have situation when server can return html instead of json when service isn't available.
$.getjson()
fails when response text/html
. see example:
$.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>
Comments
Post a Comment