Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
165
rated 0 times [  171] [ 6]  / answers: 1 / hits: 19873  / 11 Years ago, fri, february 7, 2014, 12:00:00

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




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




enter



what this could be?



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


More From » node.js

 Answers
30

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 = {};
}]);

[#72669] Wednesday, February 5, 2014, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
breap

Total Points: 606
Total Questions: 96
Total Answers: 108

Location: Djibouti
Member since Sun, Feb 27, 2022
2 Years ago
breap questions
Thu, Jun 24, 21, 00:00, 3 Years ago
Wed, Mar 18, 20, 00:00, 4 Years ago
Mon, Oct 7, 19, 00:00, 5 Years ago
;