2

Pardon my web skills but i have a very rudimentary problem.

I have this html form which should ideally call my /login url with post but for some reason it always sends a get request to that url and fails. I can't figure out how that is happening.

This is my html form

<!DOCTYPE html>
<html class="no-js">
<head>

    <title>Login - MobileMedic</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="description" content="">
    <meta name="author" content="" />

    <link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Open+Sans:400italic,600italic,800italic,400,600,800" type="text/css">
    <link rel="stylesheet" href="./css/font-awesome.min.css" type="text/css" />
    <link rel="stylesheet" href="./css/bootstrap.min.css" type="text/css" />
    <link rel="stylesheet" href="./css/jquery-ui-1.9.2.custom.min.css" type="text/css" />
    <link rel="stylesheet" href="./css/App.css" type="text/css" />
    <link rel="stylesheet" href="./css/Login.css" type="text/css" />
    <link rel="stylesheet" href="./css/custom.css" type="text/css" />

    <script src="./js/jquery-1.9.1.min.js"></script>
    <script src="./js/alert.js"></script>
    <script src="./js/jquery-ui-1.9.2.custom.min.js"></script>
    <script src="./js/bootstrap.min.js"></script>
    <script src="./js/plugins/parsley/parsley.js"></script>

</head>

<body>
    <div class="gifload"></div>

    <div id="login-container">

        <div id="logo">
            <a href="./index.html"> <img src="./images/logos/logo-login.png" alt="Logo" /> </a>
        </div>

        <div id="login">

            <h3>Welcome to Apprick Technologies.</h3>

            <h5>Please sign in to get access.</h5>

            <form method="post" action="/login" id="login-form" class="form parsley-form" data-validate="parsley">
                <div class="form-group">
                    <input type="email" class="form-control" id="email" placeholder="Email" required="required">
                </div>

                <div class="form-group">
                    <input type="password" class="form-control" id="password" placeholder="Password" required="required">
                </div>

                <div class="form-group">
                    <input type="submit" class="btn btn-primary btn-block" name= "Signin" value="Signin"/>
                </div>

            </form>

        </div>
    </div>
    <!-- /#login-container -->
</body>

To make the question more clear i use express js with parse.com and here are the two routing defined

app.get('/login', function(req, res) {
    res.send('get is called');
});

app.post('/login', function(req, res) {
    res.send('post is called');
});

Now no matter what i provide in my form method i always get "get is called" in the browser on submitting the button.

I also tried to debug what is happening in by the developer console and this is what i get

enter image description here

Raghvendra Singh
  • 1,775
  • 4
  • 26
  • 53
  • 1
    Weird, got an online example? – James Hunt Jul 03 '14 at 06:27
  • 1
    What is making you think the form is sending a GET request? What do you mean it "fails?" (What fails?) –  Jul 03 '14 at 06:30
  • Try to narrow down the issue. My first try would be: remove all JavaScript. – SimonSimCity Jul 03 '14 at 06:32
  • The reason i am saying it sends a get request is because when i click submit the browser shows me page not found (it tries to get http://xxxxxxxxxxx.com/login) – Raghvendra Singh Jul 03 '14 at 06:40
  • i removed all javascript but still i see the same problem – Raghvendra Singh Jul 03 '14 at 06:45
  • @RaghvendraSingh Whether you send a GET or POST request, if there is no resource at the location you are accessing, you will see an error like "page not found." The problem you're having is your server has no resource at `/login` to handle the form you're submitting. –  Jul 03 '14 at 08:07
  • @TomDworzanski, thats not true. I edited the question with more info. the browser does sends a post request only and its found too, but somehow it gets redirected to get with status code 302. – Raghvendra Singh Jul 03 '14 at 08:10
  • @RaghvendraSingh Your Express.js code is fine and should return "post is called" as you say. Yet something is causing this redirect. Sometimes redirects get cached and cause strange problems. There might also be something else in your stack triggering the redirect (a parse.com library?). I don't know enough about parse.com or how to use their system to offer any better advice. But I do know, as you have now shown, the form is correctly sending a POST request, so the issue isn't there. –  Jul 03 '14 at 08:19
  • @RaghvendraSingh On second thought, did you notice in Chrome's developer tools that the little icon next to the GET request to parse.com has a logo with `<>` in it. I think this means the GET request is being made via AJAX (probably through one of your scripts), not by your server. These could be two independent requests. Look over your headers closely. –  Jul 03 '14 at 08:25
  • @TomDworzanski, thanks a ton. I will be posting a question on parse.com – Raghvendra Singh Jul 03 '14 at 16:26
  • The answer to this question I have provided [here][1] on stackoverflow [1]: http://stackoverflow.com/a/26458185/1087841 – Saad Oct 20 '14 at 03:29

1 Answers1

0

I tried your code and it is working as a "POST" request. Try changing your request to "GET" and you can notice in the URL that it has something like this at the end "?Signin=Signin".

Include a "name" attribute to your input tags.

Sample:

<input type="email" name="email" class="form-control" id="email" placeholder="Email" required="required">

And you can see something like this upon submitting the form:

/login?email=testemail%40test.test&Signin=Signin
Tonned
  • 286
  • 2
  • 9