0

I'm doing an AJAX request to submit a form:

<form id="ajax-contact" role="form" action="signup.php" method="post">

And for javascript something like this:

$(function() {
    // Get the form.
    var form = $('#ajax-contact');
    ...

    $.ajax({
        type: 'POST',
        url: $(form).attr('action'),
        data: formData
    }).done(function(response) 
        ...
    }).fail(function(data) {
        ...
    });
});

Using the Chrome inspect element I see that this message after submitting:

Error: POST http://localhost:9000/signup.php 404 (Not Found)

However, if I click on the link in the error message it downloads the correct signup.php, so I know the file exists at that location.

Any idea of what I'm doing wrong?

bcorso
  • 45,608
  • 10
  • 63
  • 75
  • Try with full path. It seems it goes outside your project folder. It should be like localhost/yourproject/signsignup.php – RN Kushwaha Sep 21 '14 at 02:36
  • So the browser downloads the `signup.php` file instead of running it? http://stackoverflow.com/q/18422140/1144203 – ivan.sim Sep 21 '14 at 02:38
  • @isim, no it just gives 404, but if i click on the error message it downloads the correct file – bcorso Sep 21 '14 at 02:43
  • @bcorso So if the link in your error message is `http://localhost:9000/signup.php`, it still shouldn't download your PHP file. – ivan.sim Sep 21 '14 at 02:46
  • @isim, regardless of what it should do when I click it, what I'm trying to say is that the error message says it's not found but when I click on it the file is downloaded; therefore it must be there. – bcorso Sep 21 '14 at 02:58
  • @bcorso, are you using Skype? If so, can you switch it off and do a test with the default port? – Lajos Arpad Sep 21 '14 at 03:29

1 Answers1

0

First thing first: Check you web server's (apache/nginx) error log! This should tell you more!

Is PHP getting called? When you say it downloaded the signup.php file did you mean a "file" got downloaded? If so then check your web server's configuration. Seems like it's not executing PHP for that file and hence server is sending the file itself instead of calling PHP process.

Ahsan
  • 3,845
  • 2
  • 36
  • 36
  • (1) the setup I have right now is only running on node.js, not apache or nginx. (2) when I click submit it returns a 404 not found error. It only downloads the file when I open a new tab and try to go to the url it says it could not find, i.e. "http://localhost:9000/signup.php". Also, if I switch the ajax method from "POST" to "GET" I get an OK 200 response. So just not sure why I can't use "POST". – bcorso Sep 21 '14 at 17:29
  • 1
    If you are using nodejs, have you registered any routing for handling that URL? If yes then check the route's http method. Another question is, why does the url have .php extension if you are not using nodejs? – Ahsan Sep 21 '14 at 17:57