admin管理员组文章数量:1287561
Hi and merry christmas to you all.
I am working with a Phonegap AngularJS App. I am trying to make an http Post but I it returns an 404 error. I tried the POST using jquery 1.10.2 and it works. I have been days in this and it is the last part to finish coding the app.
I have tried different versions of the request with no success.
Here is the code
$scope.sendMail = function (user){
console.log('sendmaul');
$http.post('https://cloud/email.aspx',
{
user: user.email,
pass: user.password,
to:user.recipient,
subject:'Test',
message:'My Message'
}
)
.success(function (data, status, headers, config){
console.log('success');
})
.error(function (data,status,headers,config){
console.log(data + status + config);
});
}
I have read in many places that I need to add on a angular.module the following code as .config
$httpProvider.defaults.useXDomain = true;
delete $httpProvider.defaults.headersmon['X-Requested-With'];
I added that code on controller.js but I don't see difference on behavior in my app. I also have many http.get() request that work really well.
--EDIT--
is not a real site.
Hi and merry christmas to you all.
I am working with a Phonegap AngularJS App. I am trying to make an http Post but I it returns an 404 error. I tried the POST using jquery 1.10.2 and it works. I have been days in this and it is the last part to finish coding the app.
I have tried different versions of the request with no success.
Here is the code
$scope.sendMail = function (user){
console.log('sendmaul');
$http.post('https://cloud/email.aspx',
{
user: user.email,
pass: user.password,
to:user.recipient,
subject:'Test',
message:'My Message'
}
)
.success(function (data, status, headers, config){
console.log('success');
})
.error(function (data,status,headers,config){
console.log(data + status + config);
});
}
I have read in many places that I need to add on a angular.module the following code as .config
$httpProvider.defaults.useXDomain = true;
delete $httpProvider.defaults.headers.mon['X-Requested-With'];
I added that code on controller.js but I don't see difference on behavior in my app. I also have many http.get() request that work really well.
--EDIT--
https://cloud.email.aspx is not a real site.
Share Improve this question edited Dec 24, 2013 at 12:27 JocisPR asked Dec 23, 2013 at 21:08 JocisPRJocisPR 3371 gold badge3 silver badges10 bronze badges 5- 1 Have you looked @ network traces / debuggers to see what the differences in your request is with jquery and angular? Have you tried curl? – NG. Commented Dec 23, 2013 at 21:10
- I am testing inside my app because when testing locally I get No 'Access-Control-Allow-Origin' so it is very difficult to check anything else. This is my first app so I don't know how to implement curl with angular. If I remove POST method I get a 405. thanks for the response. – JocisPR Commented Dec 23, 2013 at 21:43
- It seems a CORS problem. – JocisPR Commented Dec 23, 2013 at 22:24
- I solved my CORS problem and I get a 200 status but it seems that DATA does not arrive. Again, jquery 1.10.2 works like a charm – JocisPR Commented Dec 30, 2013 at 13:14
-
Ha ha, did
sendmaul
make anyone else smile? – Douglas Ludlow Commented Jul 29, 2016 at 16:43
1 Answer
Reset to default 8Solved my problem.
After adding CORS and some Origins Exceptions on server side. I tried my code and got Success and 200 status response but the web service did nothing. After reading this other stackoverflow post I found out that Angularjs post data different from jquery so a normal POST read on the web service would not work. That post have a link to this site which explain in more detail my issue and it has some code for to send data the same way jquery does.
I hope this help someone
本文标签: javascriptAngularJS httppost() returns 404Stack Overflow
版权声明:本文标题:javascript - AngularJS http.post() returns 404 - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741310585a2371627.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论