Home > other >  Cannot GET /<path>
Cannot GET /<path>

Time:07-09

I have a form in a handlebars file that sends a GET request to '/result'. In my main js file I have an app.get() handler for the path '/result'. However when I send the form I just see "Cannot GET /result". I've tried using POST and I get "Cannot POST /Result".

in main.handlebars

<form action='/result' method="get">

    {{#each questions}}
        <p>{{q}}</p><br>

        <input type="radio" id={{a1}} name={{q}} value="1" >
        <label for={{a1}}>{{a1}}</label><br>

        <input type="radio" id={{a2}} name={{q}} value="2" >
        <label for={{a2}}>{{a2}}</label><br>

        <input type="radio" id={{a3}} name={{q}} value="3" >
        <label for={{a3}}>{{a3}}</label><br>

        <input type="radio" id={{a4}} name={{q}} value="4" >
        <label for={{a4}}>{{a4}}</label><br>
    {{/each}}

    <input type="submit" value="Get Result">

</form>

in interface.js

app.get('/result', function(req, res)
    {
        // calculate result (r1, r2, r3, or r4)
        quizResult = "r4"

        // load page
        res.render('result', {layout: 'index', content: quizContent(), result: quizResult});  
        
    });

in result.handlebars

{{!-- title and description --}}
<h3>Your result is...</h3>
<h1 id="result"></h1>

CodePudding user response:

You must provide more info about how your app works. You have handlebars in node, or you are using node as api? From your example I assume you are using https://github.com/express-handlebars/express-handlebars this lib?

You should try to open /result page manually if it works and then search for problems in form submitting.

CodePudding user response:

It ended up being an issue with a JSON object I was passing to handlebars to use in the form, and that must have prevented the GET request from actually being sent. Fixed the JSON syntax and now the page loads.

  • Related