Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can't get errors after a post request #213

Closed
scerelli opened this issue Jan 27, 2016 · 5 comments
Closed

can't get errors after a post request #213

scerelli opened this issue Jan 27, 2016 · 5 comments

Comments

@scerelli
Copy link

I'dont know if this (#41) is fixed or not but i've this situation:

login(email = '', password = '') {
    let request = axios({
      url: api.session,
      method: 'post',
      data: {
        user: {
          email: email,
          password: password
        }
      },
      headers: {
        'Content-Type': 'application/json',
        'X-Requested-With': 'XMLHttpRequest'
      }
    })
    .catch(reason => {
      console.log(reason)
      return reason;
    })
    .then(function(response){
      console.log(response)
      return response;
    })
  }

but what i see is that the response arrives only if the status is 200 otherwise it doesn't enter in catch and even in then it just stops.

this is what i see when i try to enter wrong credentials in my form:

XMLHttpRequest cannot load http://url/session. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8088' is therefore not allowed access. The response had HTTP status code 401.

EDIT:

this is my setup:

axios.defaults.headers.post['Content-Type'] = 'application/json';
axios.defaults.headers.post['Accept'] = 'application/json';
axios.defaults.transformRequest = [(data) => JSON.stringify(data.data)];
@mzabriskie
Copy link
Member

Sounds like you're having a problem with CORS. Make sure that your server is setting the headers correctly to accept requests from other origins.

@scerelli
Copy link
Author

It's strange because i get this error only if user and pass are wrong otherwise if i type correct login data the promise works well because the server return 200

@renan-m-p
Copy link

If you dont have access to configure CORS on the server, and are you using
Google Chrome you can use this extension:
https://chrome.google.com/webstore/detail/allow-control-allow-origi/nlfbmbojpeacfghkpbjhddihlkkiljbi
worked
for me yesterday.

Em qua, 27 de jan de 2016 às 14:58, Stefano notifications@github.com
escreveu:

It's strange because i get this error only if user and pass are wrong
otherwise if i type correct login data the promise works well because the
server return 200


Reply to this email directly or view it on GitHub
#213 (comment).

@scerelli
Copy link
Author

Good one

@peterkracik
Copy link

Hi I have the same problem.
I've just switched from jquery ajax to axios, but I can't make it works.

$.post(url, params, function() {...}); -> works great

axios({
method: 'post',
url: url,
data: params,
headers: {
'Content-Type': 'application/json'
}
});

doesnt work. I get allways 'method non allowed' error, and I dont know why, but it sent as request method "OPTIONS" not "POST".
and I cant see my parameters either.
Am I missing something? any solution?
it needs to be POST and 'Content-Type': 'application/json'.

thanks

@axios axios locked and limited conversation to collaborators May 21, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants