加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Ajax / php – 如何返回失败

发布时间:2020-12-15 23:13:37 所属栏目:百科 来源:网络整理
导读:jquery允许成功失败和错误响应.如何手动返回故障或错误以及描述故障或错误的字符串? 解决方法 使用简单的 JSON信封报告服务器端发生的故障(不是HTTP错误)已经成为一种惯例. flickr api提供了一个典型的包装示例: look at the bottom of this page for succ
jquery允许成功失败和错误响应.如何手动返回故障或错误以及描述故障或错误的字符串?

解决方法

使用简单的 JSON信封报告服务器端发生的故障(不是HTTP错误)已经成为一种惯例.

flickr api提供了一个典型的包装示例:

look at the bottom of this page for success and failure examples

因此,在对flickr API进行Ajax调用的情况下,在成功回调中,您将检查返回的数据是否成功/失败

$.ajax({   
  //...   
  success:   function(data) {
    if(data.stat == 'fail') {
       //data.code + data.message contain details that could be used here
    }
    else {
      //do success stuff here
    }
  }
});

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读