最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - GET http:localhost:3000publicjstest.js net::ERR_ABORTED 404 (Not Found) - Stack Overflow

programmeradmin0浏览0评论

I tried to connect sign_up.liquid with test.js. But I have the error 404.

I think my path to connect this two files are correct:

  <script src="../../public/js/test.js"> </script>
  <form id="formSignUp" method="POST" onsubmit="return main()">
    <h1>Inscription</h1>
    <input type="text" id="form_input_name" name="name" placeholder="Prénom" size= "30">
    <input type="text" id="form_input_surname" name="surname" placeholder="Nom" size= "30">
    <input type="text" id="form_input_mail" name="mail" placeholder="E-mail" size= "30">
    <input type="password" id="form_input_password" name="password" placeholder="Mot de passe" size= "30">
    <input type="password" id="form_input_conf_password" name="conf_password" placeholder="Confirmation de mot de passe" size= "30">

    <div id="div_checkNewsletter">
        <input type="hidden" name="newsletter" value="0">
        <input type="checkbox" id="box_newsletter" name="newsletter" value="1">
        <label for="newsletter">En cochant cette case, j’accepte de recevoir <br>les actualités d’Otablo.</label>
    </div>

    <button type="submit" id="button_orange_center"> Suivant</button>
</form>

And my server.js make a way to send my static files to the client:

const express = require('express')
const app = express()
const path = require('path')
const bodyParser = require('body-parser')
const http = require('http').createServer(app)

// Liqui Param
const { Liquid } = require('liquidjs')
const engine = new Liquid({
  root: ['./views', './views/partials', './views/layouts']
})

const HTML_DIR = path.join(__dirname, '/public/')
app.use(express.static(HTML_DIR))

app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: true }))

I don't understand why sign_up.liquid and test.js are not linked.

I tried to connect sign_up.liquid with test.js. But I have the error 404.

I think my path to connect this two files are correct:

  <script src="../../public/js/test.js"> </script>
  <form id="formSignUp" method="POST" onsubmit="return main()">
    <h1>Inscription</h1>
    <input type="text" id="form_input_name" name="name" placeholder="Prénom" size= "30">
    <input type="text" id="form_input_surname" name="surname" placeholder="Nom" size= "30">
    <input type="text" id="form_input_mail" name="mail" placeholder="E-mail" size= "30">
    <input type="password" id="form_input_password" name="password" placeholder="Mot de passe" size= "30">
    <input type="password" id="form_input_conf_password" name="conf_password" placeholder="Confirmation de mot de passe" size= "30">

    <div id="div_checkNewsletter">
        <input type="hidden" name="newsletter" value="0">
        <input type="checkbox" id="box_newsletter" name="newsletter" value="1">
        <label for="newsletter">En cochant cette case, j’accepte de recevoir <br>les actualités d’Otablo.</label>
    </div>

    <button type="submit" id="button_orange_center"> Suivant</button>
</form>

And my server.js make a way to send my static files to the client:

const express = require('express')
const app = express()
const path = require('path')
const bodyParser = require('body-parser')
const http = require('http').createServer(app)

// Liqui Param
const { Liquid } = require('liquidjs')
const engine = new Liquid({
  root: ['./views', './views/partials', './views/layouts']
})

const HTML_DIR = path.join(__dirname, '/public/')
app.use(express.static(HTML_DIR))

app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: true }))

I don't understand why sign_up.liquid and test.js are not linked.

Share Improve this question edited Dec 17, 2019 at 15:28 Adrian Mole 52k192 gold badges59 silver badges97 bronze badges asked Dec 17, 2019 at 14:41 MynoMyno 1583 silver badges14 bronze badges 1
  • The HTML5 placeholder attribute is not a substitute for the label element – Quentin Commented Dec 17, 2019 at 14:50
Add a ment  | 

1 Answer 1

Reset to default 3

I think my path to connect this two files are correct

It isn't.

The path is what you specify in your server.js file and not on your puters file system.

You said:

const HTML_DIR = path.join(__dirname, '/public/')
app.use(express.static(HTML_DIR))

… so everything in /public/ gets mapped to URLs under /.

That means the path is:

src="/js/test.js"
发布评论

评论列表(0)

  1. 暂无评论