AngularJS http.post() returns 404
Solved 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
JocisPR
New to programming and hardworking though I need more Intelligence to keep going since I am not that good at what I do. I have used js, php, java, .net, visual basic, c#, razor, mysql, mssql, grails, html5 and more that I cannot remember right now.
Updated on June 04, 2022Comments
-
JocisPR almost 2 years
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.common['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.
-
Radu Andrei over 9 yearsDude, props to you! Fallowed the trail and got the damn explanation in the end. Thank you!