2021年1月1日星期五

Can anyone explain why my program is not showing the correct alert?

I have written this function which allows users to add images to the server. However, my alerts don't seem to be working. I've tried to console.log the alert messages instead of having them as alerts but that doesn't seem to work either. Any tips would be great. client.js

async function picsub(event){      event.preventDefault();      var image=document.getElementById('imageFile');      const formData = new FormData();;      formData.append('image',image.files[0]);      let i={          method:'POST',          body:formData,        }      fetch('http://127.0.0.1:8090/pics', i).then((response) => {          return response.text();      }).then((response) => {          if (response === 'success') {              alert('pic added');          } else {              alert('An error has occurred');          }      }).catch((e) => {          alert('An error has occurred');            form.reset();    }    const form = document.getElementById("form");  form.addEventListener("submit", picsub);  

server.js

const app = express();  const port = 8090;    let pictures=[];    app.post('/pics', (req, res) => {      const pic = req.body;      console.log(pic);      pictures.push(pic);      res.status(201);  });    
https://stackoverflow.com/questions/65535384/can-anyone-explain-why-my-program-is-not-showing-the-correct-alert January 02, 2021 at 09:52AM

没有评论:

发表评论