1

I am using AngularJS on Rails in order to make a POST request to another webiste for authenticatng users' login. However, I received CORS error and got a 405 error.

What will be the best way to send a POST request on login in Rails?

Yumiko
  • 448
  • 5
  • 16
  • And you are positive that this site allows `POST`s? – Borsunho Aug 12 '15 at 07:06
  • @Borsunho the API document says "POST /api/user/token", so I believe it accepts POST method. – Yumiko Aug 12 '15 at 07:40
  • @BradWerth Even I tried `$httpProvider.defaults.useXDomain = true; delete $httpProvider.defaults.headers.common['X-Requested-With'];` It still getting the same error. – Yumiko Aug 12 '15 at 07:43

1 Answers1

1

This is happening as a security reason because your browser doesn't allow you to send ajax call on other domain.

But however you can achieve that using jsonp. You haven't provided your code sample so i can't say exactly but following should solve your problem :

//add ?callback=jsonp_callback after your url
// e.g my url is www.xyz.com/abc then
var url = "www.xyz.com/abc?callback=JSON_CALLBACK";

$http.jsonp(url).
    success(function(data, status, headers, config) {
        //success
    }).
    error(function(data, status, headers, config) {
        //error
    });
Juned Lanja
  • 1,466
  • 10
  • 21