Warm tip: This article is reproduced from serverfault.com, please click

Can not read http request properly

发布于 2020-11-29 03:09:33

I'm trying to update the data with using by axios, and I want to use "id" in request url like http://localhost/api/firstmemory/1

but return 500 Internal Server Error, because my id does not read prpoerly. enter image description here

my code

    const id = detail.id;

    const updateFirstInfo = (e) => {
    const upInfo = {
        first: first,
        date: change,
        memo: memo,
    }
    console.log(id); //1
   
    axios
      .put(`api/firstmemory/${id}}`, upInfo)
      .then(res => {
        console.log("ok");
      })
      .catch(err => {
        alert("err");
      });
  };

How can I fix it?

Questioner
knkn
Viewed
0
Alexander Staroselsky 2020-11-29 11:13:34

%7D is the HTML encoding for character }. If you look carefully you have an extra } where you were using template strings. Remove the extra }:

axios
  .put(`api/firstmemory/${id}`, upInfo)
  .then(res => {
    console.log("ok");
  })
  .catch(err => {
    alert("err");
  });

Hopefully that helps!