简体   繁体   中英

How to catch ajax error response?

when i have an ajax error response with jquery i have the following log:

jquery.js:8630 OPTIONS http://10.0.1.108:8000/api/v1.0/auth/ net::ERR_CONNECTION_REFUSED
Object {readyState: 0, status: 0, statusText: "error"}

In my object i have a property statusText: 'error' , but no properties with 'net::ERR_CONNECTION_REFUSED' .

I tried to log the responseText as see here Get server response with AJAX error? but my object didn't have this property;

Do you know how i can get it in javascript please? Thank.

You can't.

Many errors, including most (if not all) status: 0 errors, are not exposed to JavaScript.

They indicate network or same origin policy errors and exposing the details to JavaScript could leak information. For example, if it was possible to distinguish between "Connection Refused", "Post doesn't speak HTTP" and "No Access-Control-Allow-Origin header", then it would be trivial to write a page that would quietly map out all the webservers on the visitor's corporate network. That information could then be used for phishing attacks.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM