... index.html <body> <h1>upload test</h1> <!--<form method="post" enctype="multipart/form-data" action="/picture"> --> <form id="pictureForm" method="post" enctype="multipart/form-data"> <div> <label for="file">Choose file to upload</label> <input type="file" name="file" id="pictureFile" multiple> </div> <div> <button>Submit</button> </div> </form> <script src="https://unpkg.com/axios/dist/axios.min.js"></script> <script src="./upload.js"></script> </body> ... upload.js ... await axios({ method: 'post', url: '/upload', data: formData, headers: { 'Content-Type': 'multipart/form-data', }, }) ... server.js ... app.get('/', async (req, res, next) => { try { res.writeHead(200, { 'Content-Type': 'text/html' }); const data = await fs.readFile('../index.html') res.write('Hello nodejs'); res.end(data); next(); } catch (err) { console.error(err); } }); app.post('/upload', upload.single('file'), async (req, res, next) => { try { res.send('work'); <-- not working } }); ...Estoy haciendo un servidor de carga de imágenes. y yo éxito. puedo cargar la imagen en el directorio particular que quiero.
el problema es que quiero ver la frase 'éxito' usando res.end() (o res.send, etc.). ¡pero la página web no cambió!
ingrese la descripción de la imagen aquí
correctamente, la web obtuvo la respuesta. pero no sé cómo mostrar esta respuesta en la página.
por favor enséñame.
En la interfaz puedes hacer algo como esto
fetch("http://localhost:5500/upload", requestOptions).then(response => response.text())