无法检测403状态code jQuery的AJAX调用 [英] Unable to detect 403 status code in jquery AJAX call

查看:174
本文介绍了无法检测403状态code jQuery的AJAX调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用下面的code调用在端口9084其他用户的计算机上的应用程序(缺乏DEV服务器)。这是一个Java应用程序,我想从我的ASP.Net应用程序调用(它使用母版页)。我想打电话给下面将在cookie中返回一个403错误状态和会话ID的URL。我想利用这个会话ID,并使用应用程序ID和密码拨打另一个电话。

当我使用URL的http:fwdslash fwdslash机器名称:9084 fwdslash PropertyInsuranceDB fwdslash propertyAssociation fwdslash阿贾克斯fwdslash getPolicyAddress fwdslash H0271812 fwdslash 08在浏览器中,我得到的HTTP 403禁止错误页面。当我尝试在code下面,我看到提琴手是相同的,但我不能够捕获它在下面的AJAX调用的错误部分。

还有什么我是做错了什么?任何建议将大大AP preciated。

  $阿贾克斯(网址:{url:HTTP://机器:9084 / PropertyInsuranceDB / propertyAssociation / AJAX / getPolicyAddress / H0271812 / 08,
            背景:document.body的,
            键入:搞定,
            成功:功能(数据,状态){
                警报(状态);
            },
            错误:功能(XHR,递减,ERR){
                警报(xhr.status);
                警报(DESC);
                警报(ERR);
            }
        });

感谢

- Nivedita

解决方案

如果服务器返回的东西,它通常被认为是成功的Ajax调用,即使它不返回你想让它返回的内容。

要赶上状态codeS,你可以做

  $阿贾克斯({
     网址:YOURURLHERE
     背景:document.body的,
     键入:搞定,
     状态code:{
         403:功能(XHR){
             的console.log('403响应');
         }
     },
     成功:功能(数据,状态){
         警报(状态);
     },
     错误:功能(XHR,递减,ERR){
         警报(xhr.status);
         警报(DESC);
         警报(ERR);
     }
 });

I am using the following code to invoke an application on another users machine on port 9084 (for the lack of a DEV server). This is a JAVA application that I would like to call from my ASP.Net application (it uses master pages). I would like to call the URL below which will return a 403 error status and a session ID in a cookie. I would like to use this session ID and make another call using an application ID and password.

When I use the URL "http:fwdslash fwdslash machinename:9084 fwdslash PropertyInsuranceDB fwdslash propertyAssociation fwdslash ajax fwdslash getPolicyAddress fwdslash H0271812 fwdslash 08" in the browser, I get the HTTP 403 Forbidden error page. When I try the code as below, I see the same in Fiddler, but I am not able to trap it in the error section of the ajax call below.

What could I be doing wrong? Any suggestions will be greatly appreciated.

$.ajax({   url: "http://machinename:9084/PropertyInsuranceDB/propertyAssociation/ajax/getPolicyAddress/H0271812/08",
            context : document.body,
            type: "get",
            success: function (data, status) {
                alert(status);
            },
            error: function (xhr, desc, err) {
                alert(xhr.status);
                alert(desc);
                alert(err);
            }
        });

Thanks

--Nivedita

解决方案

If the server returns something, it's usually considered a successful ajax call, even if it doesn't return what you want it to return.

To catch the status codes you can do

    $.ajax({
     url: "YOURURLHERE",
     context: document.body,
     type: "get",
     statusCode: {
         403: function (xhr) {
             console.log('403 response');
         }
     },
     success: function (data, status) {
         alert(status);
     },
     error: function (xhr, desc, err) {
         alert(xhr.status);
         alert(desc);
         alert(err);
     }
 });

这篇关于无法检测403状态code jQuery的AJAX调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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