1

When a user enters some details I am trying to add them to the database via a POST to a file called registerNewUser.php However the POST never succeeds. I'm simply given a 404. Here is the post code:

$http({
    method: 'POST',
    url: '../../php/login/registerNewUser.php',
    data: newUser,
    headers: {
        'Content-Type': 'application/x-www-form-urlencoded'
    }
}).success(function(data, status) {
    console.log("success");
}).error(function(status) {
    console.log("ERROR");
});

I have tried moving setting the url to /registerNewUser.php and moving registerNewUser.php to the base directory but still no luck. Any help would be greatly appreciated.

Mohamad Shiralizadeh
  • 8,329
  • 6
  • 58
  • 93
  • Check the network tab for the actual URL that's being called – Patsy Issa Oct 28 '14 at 17:09
  • possible duplicate of [How do I POST urlencoded form data with $http in AngularJS?](http://stackoverflow.com/questions/24710503/how-do-i-post-urlencoded-form-data-with-http-in-angularjs) – mscdex Oct 28 '14 at 17:14
  • @mscdex not at all. OP, open debug tools, click network, send the request, click the request. Check the details. –  Oct 28 '14 at 17:16
  • The actual url being called is http://127.0.0.1:8080/registerNewUser.php. I would imagine this should work as registerNewUser.php is in the same folder as index.html and home.html. – BobDoleForPresident Oct 28 '14 at 17:27
  • Also it says that the content type is text/plain. should this be application/json? – BobDoleForPresident Oct 28 '14 at 17:37
  • Where is the html file that houses this form (and the AngularJS)? Make sure you're ignoring anyting after the # in the URL, as that is never seen by the server and ignored by the browser when calculating pathing. I'm guessing that if you set url to "/php/login/registerNewUser.php" or potentially "registerNewUser.php" it will work. If you manually type "http://yourserver/php/login/registerNewUser.php" does it work (won't be a POST, but shouldn't get 404)? – Mike Oct 28 '14 at 17:41
  • if I manually type 127.0.0.1:8080/registerNewUser.php it asks me if I want to open the php file but it also gives me a 404 on the web page. – BobDoleForPresident Oct 28 '14 at 17:56
  • looks like you need to start the php process – Dinu Sorin Oct 28 '14 at 18:26

0 Answers0