Как добавить данные из поля ввода в браузере в мой массив веб-сайтов[имя], а затем отобразить их в абзаце HTML?
server.js
import express from "express"
import { websites } from "./websites.js"
import { fileURLToPath } from 'url';
import { dirname } from 'path';
import * as http from 'http'
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const server = express();
server.use(express.json());
server.get("/last", (req,res) =>{
res.sendFile("index.html", {root: __dirname});
})
server.post("/last", (req,res) => {
var DataG = req.body.name;
http.get({host: DataG}, function(response){
console.log(response.statusCode)
if(response.statusCode < 400)
console.log("server is up")
else{
console.log("server is down")
}
});
res.send("Request processed");
})
index.html
Submit
let pisun = document.getElementById("pisun")
let pisunchik1 = document.createElement("p").textContent = "nothing"
let websiteName = document.querySelector(".text")
let button = document.querySelector(".subBtn")
if(button)
{
button.addEventListener("click", () =>{
let obj = {
name:websiteName.value
};
fetch("http://localhost:3000/last",{
method:"POST",
headers:{
"Content-type":"application/json"
},
body:JSON.stringify(obj)
})
})
}
websites.js («db»)
export const websites = [
{name:"google", enable: true},
{name:"bing", enable: true},
];
Подробнее здесь: https://stackoverflow.com/questions/798 ... ame-and-th
Как добавить данные из поля ввода на стороне клиента в мой массив веб-сайтов [имя], а затем отобразить их в html-докумен ⇐ Html
Программисты Html
1761840617
Anonymous
Как добавить данные из поля ввода в браузере в мой массив веб-сайтов[имя], а затем отобразить их в абзаце HTML?
[b]server.js[/b]
import express from "express"
import { websites } from "./websites.js"
import { fileURLToPath } from 'url';
import { dirname } from 'path';
import * as http from 'http'
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const server = express();
server.use(express.json());
server.get("/last", (req,res) =>{
res.sendFile("index.html", {root: __dirname});
})
server.post("/last", (req,res) => {
var DataG = req.body.name;
http.get({host: DataG}, function(response){
console.log(response.statusCode)
if(response.statusCode < 400)
console.log("server is up")
else{
console.log("server is down")
}
});
res.send("Request processed");
})
[b]index.html[/b]
Submit
let pisun = document.getElementById("pisun")
let pisunchik1 = document.createElement("p").textContent = "nothing"
let websiteName = document.querySelector(".text")
let button = document.querySelector(".subBtn")
if(button)
{
button.addEventListener("click", () =>{
let obj = {
name:websiteName.value
};
fetch("http://localhost:3000/last",{
method:"POST",
headers:{
"Content-type":"application/json"
},
body:JSON.stringify(obj)
})
})
}
[b]websites.js[/b] («db»)
export const websites = [
{name:"google", enable: true},
{name:"bing", enable: true},
];
Подробнее здесь: [url]https://stackoverflow.com/questions/79803794/how-to-add-data-from-a-client-side-input-field-to-my-array-websitesname-and-th[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия