5

This is my Angular js piece code:

$http({
                method:'POST',
                withCredential:true,
                url:$scope.config.app_ws+'auth/signup',
                data:{user:$scope.auth}
            }).success(function(status, response){

                console.log(response);
            }).error(function(status, response){
                alert(response+'Bummer :( , an error occured plese retry later. ');
            });

This is my Node.js piece backend:

 var allow_cross_domain= function(req, res, next) {
      res.header('X-Powered-By', 'hey.heyssssssss.org');

      var oneof = false;
      if(req.headers.origin) {
        res.header('Access-Control-Allow-Origin', req.headers.origin);
        oneof = true;
      }
      if(req.headers['access-control-request-method']) {
        res.header('Access-Control-Allow-Methods', req.headers['access-control-request-method']);
        oneof = true;
      }
      if(req.headers['access-control-request-headers']) {
        res.header('Access-Control-Allow-Headers', req.headers['access-control-request-headers']);
        oneof = true;
      }
      if(oneof) {
        res.header('Access-Control-Max-Age', 60 * 60 * 24 * 365);
      }
    // intercept OPTIONS method
    if (oneof && req.method == 'OPTIONS') {
      res.send(200);
    } else {
      next();
    }
    }

    app.use(allow_cross_domain);

    app.post('/auth/signup', function (req, res) { res.send('wtff'); });

I'm just calling POST localhost:3000/auth/signup from Angular to Node, but i get **CAUTION : Provisional headers are shown.** in chrome console.

Chrome (CAUTION):

enter image description here

Firefox (NO RESPONSE for about 30/60 seconds and then the alert() comes up :/ ):

enter image description here

what this could be?

IF i use GET everything is ok, is just with POST that i get troubles how is that possible?

0

2 Answers 2

10

personaly I use this "reset" method in angular:

app.config(['$httpProvider', function ($httpProvider) {
  //Reset headers to avoid OPTIONS request (aka preflight)
  $httpProvider.defaults.headers.common = {};
  $httpProvider.defaults.headers.post = {};
  $httpProvider.defaults.headers.put = {};
  $httpProvider.defaults.headers.patch = {};
}]);
Sign up to request clarification or add additional context in comments.

7 Comments

gosh it's half a day i'm on this bug, thank you it WORKS!!
no problem. Spent lots of time looking for the answer myself
It we be cool if we could know why this happens.
No request is sent to server when this problem occurs. You may check out this SO question. It uses Jquery AJAX to communicate with PHP. It would be great if someone could help.
It is not working for me. Anyone have solution?
|
3

this was fixed Mar 28, 2014 so it will be ok in next version of crome (v35)

chromium community

2 Comments

Awesome, but it's still useful for mobile apps coding.
I am using Chrome 43, still facing this issue.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.