Skip to content

Latest commit

 

History

25 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

node

minimal node full-stack a 11i-nek

Futtatás:

npm start

Szerver oldal:

server.js

const express = require('express')
const app = express()
const port = 3000
app.use(express.static('static'))
app.use(express.urlencoded({extended: true}))
app.post('/', (req, res) => {
    p = Math.round(Math.random()*10+1)
    console.log(req.body, p)
    res.send({x: Number(req.body.x) + p})
})
app.listen(port, () => {
  console.log(`Listening on port ${port}`)
})

Kliens oldal:

static/index.js:

$(() => {
    $("#b1").click( e => {
        data = {x: Math.round(Math.random()*10+1)}
        $.post("/", data, (res) => {
            $("#o").html(res.x) 
        })
    } )
})

static/index.html:

<!DOCTYPE html>
<html lang="en">
<head>
    <script src="jquery.min.js"></script>
    <script src="index.js"></script>
    <link rel="stylesheet" href="index.css">
    <meta charset="UTF-8">
</head>
<body>
    <button id="b1">katt</button>
    <div id="o">-</div>
</body>
</html>

static/index.css

body {
    background-color: aquamarine;
}
div#o {
    text-align: center;
    font-size: 30px;
}

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages