0

I have a rest API and when I call it in chrome console return this error:

Response for preflight is invalid (redirect)

But when I test this API in Postman everything is ok and work correctly.

this my code:

$.ajax({
type: 'GET',
dataType:'json', 
headers: {
    "Authorization":"Basic Ym86Ym8=",
    "Accept":"application/json",
    "Content-Type":"application/json"
},
contentType: 'application/json; charset=utf-8',
success(data, response) {
    console.log(data, response);
},
url: 'http://##########/bo/api/v1/transactions/',
});

How i can fix this error?

enter image description here

Arman Feyzi
  • 788
  • 2
  • 11
  • 28
  • you have to add `Access-Control-Allow-Origin` in your api CORS settings or filter what ever you are using – Muhammad Omer Aslam May 12 '18 at 12:11
  • Do you control the api code? If not use a proxy on server you control to make the api request. Postman is not restricted to CORS security the way browsers are – charlietfl May 12 '18 at 12:12
  • have look in : https://stackoverflow.com/questions/33645511/why-my-ajax-showing-preflight-is-invalid-redirect-error – SayJeyHi May 12 '18 at 12:21
  • `Access-Control-Allow-Origin` setting is already set, when test this API with online Rest-API tester also work correctly, only in browser I get this error – Arman Feyzi May 12 '18 at 12:23
  • Your request results in a CORS preflight (an OPTIONS request) - does the API handle CORS preflight at all? – Jaromanda X May 12 '18 at 12:24
  • @JaromandaX yes, I update my question – Arman Feyzi May 12 '18 at 12:28
  • 1
    but your API (it is yours?) "handles" responds to OPTIONS request with a `302` redirect - which is exactly the issue – Jaromanda X May 12 '18 at 12:51
  • And if it is not yours use a server side proxy as mentioned above. It really seems like that API is not CORS enabled. Many aren't especially if they want you to keep credentials secure – charlietfl May 12 '18 at 13:02

0 Answers0