[removed] How to tell whether AJAX response is JSON

后端 未结 5 1719
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-29 02:22

I\'ve got an AJAX request that expects JSON in response.

But there\'s a possibility that what gets returns may not be JSON, but rather an HTML error page (unfortunat

5条回答
  •  庸人自扰
    2020-12-29 02:54

    try {
        jQuery.parseJson(json_string_here);
    } catch(e) {
       ... malformed json ...
    }
    

提交回复
热议问题