如何在jQuery getJSON调用中捕获400响应 [英] How to catch a 400 response in jQuery getJSON call

查看:123
本文介绍了如何在jQuery getJSON调用中捕获400响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在jQuery中,我想使用 $。getJSON()方法从Facebook获取一些数据,但如果令牌无效,Facebook将返回400状态。如何捕获 $。getJSON()中的错误而不是 $ .ajax()

In jQuery I want to fetch some data from facebook using the $.getJSON() method, but if the token is invalid, Facebook is returning the 400 status. How I can catch the error in $.getJSON() instead of $.ajax()?

推荐答案

我认为这对你有用

$.getJSON("example.json", function() {
  alert("success");
})
.success(function() { alert("success 2"); })
.error(function() { alert("error occurred "); })
.complete(function() { alert("Done"); });

这篇关于如何在jQuery getJSON调用中捕获400响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆