Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有以下代码
jQuery.getJSON(encodeURI(strUrl), {address:address,state:state, zip:zip},function(data){ alert('HELLO World!'); });
如果由于某种原因 strUrl 返回一个不是 JSON 格式的字符串,则永远不会调用回调函数。有没有办法知道响应是 json 格式还是帖子中出了什么问题?
jQuery.getJSON不允许您定义错误回调函数。
jQuery.getJSON
您需要改为使用jQuery.ajax,设置dataTypetojson并将剩余的配置变量设置为 getJSON 默认定义。
jQuery.ajax
dataType
json