相关疑难解决方法(0)

jQuery ajax handle 401 Unauthorized

我使用jQuery ajax调用第三方网页.根据他们的页面,他们在登录成功时发送状态代码200,如果登录失败则发送401.这是我的jquery代码示例.此代码在IE上运行正常,但在Chrome或Firefox上无效.可能是什么问题?

$.ajax({
  type: 'GET',
  url: hostURL + 'j_teo_security_check?callback=?',
  dataType: 'json',
  data: ({j_username : $("#inp_user_name").val(), j_password: $("#inp_user_pwd").val()}),
  statusCode: {
      401:function() { alert("401"); },
      404:function() { alert("404"); },
      200:function() { alert("200"); },
      201:function() { alert("201"); },
      202:function() { alert("202"); }
    },
    complete: function(httpObj, textStatus){
    alert(httpObj.status);
  },
  error: function(){
    alert("error");
  },
  async: false
});
Run Code Online (Sandbox Code Playgroud)

我尝试了所有函数错误,成功,完成和statusCode.他们都没有处理401错误.

ajax jquery jquery-mobile

24
推荐指数
1
解决办法
7万
查看次数

标签 统计

ajax ×1

jquery ×1

jquery-mobile ×1