Javascript 如何避免React fetch API替换url

Javascript 如何避免React fetch API替换url,javascript,reactjs,rest,fetch-api,Javascript,Reactjs,Rest,Fetch Api,我已经用react Fetch API发出了一个POST请求,它可以根据需要工作,只是它替换了当前页面的url 职位职能: postNote(note) { console.log('Posting note'); fetch('http://localhost:9000/notes/create', { mode: 'cors', method: 'POST', headers: { 'Accept': 'applica

我已经用react Fetch API发出了一个POST请求,它可以根据需要工作,只是它替换了当前页面的url

职位职能:

  postNote(note) {
    console.log('Posting note');

    fetch('http://localhost:9000/notes/create', {
      mode: 'cors',
      method: 'POST',
      headers: {
        'Accept': 'application/json',
        'Content-Type': 'application/json',
      },
      body: JSON.stringify(note)
    })
  }
执行此函数时,它会将我的url替换为:

我不知道为什么会发生这种情况,因为我以前使用过这个API,我没有这个问题。如果有人能给我任何帮助,我将不胜感激

提前感谢,祝你有一个美好的一周

编辑1:

我创建的注释对象如下所示:

const newNote={id:0,name:note.name,description:note.description,author\u id:note.author\u id,author:note.author}

编辑2:

postNote功能由以下功能触发:

addNote = note => {
        const newNote = {id: 0, name: note.name, description: note.description, author_id: note.author_id, author: note.author };
        this.setState({
            notas: [...this.state.notas, newNote]
        });
        console.log(newNote);

        this.postNote(newNote);
    }
编辑3:

<button className="btn btn-primary" onClick={() => {
      let newNote = { id: 0, name: this.name, description: this.description, author_id: this.author_id, author: this.author }
      noteContainer.addNote(newNote)
      }
 }>
      Save
</button>
{
让newNote={id:0,name:this.name,description:this.description,author\u id:this.author\u id,author:this.author}
noteContainer.addNote(newNote)
}
}>
拯救
内的
s触发器
提交
事件。如果您不使用
event.preventDefault()
阻止
submit
事件触发默认操作,表单将执行其正常操作;将表单数据发布到指定为
操作的任何URL

由于您试图覆盖正常功能并以自己的方式提交数据,请告诉
不要执行正常操作

document.getElementById(“foo”).addEventListener(“提交”,e=>{
e、 预防默认值();
//如果e.preventDefault()不存在,
//您可以导航到Stack Snippets主机上的some.html
//(它不存在,所以你实际上得到了404之类的东西
console.log(“你好”);
});
document.getElementById(“bar”).addEventListener(“单击”,e=>{
e、 预防默认值();
//这里也一样,只是我们阻止了点击
//事件触发更高级别的提交事件
console.log(“世界”);
});

点击我
点击我2

package.json中是否有代理?我不知道这是怎么回事。URL是硬编码的,还是由某种变量填充的。我会将该变量记录在console.log中,并确保它是用于端口9000的。您需要显示更多涉及的代码。提取本身不会导致当前页面的URL发生更改。Ho提取是否被触发?否@stever不是!这是由提交触发的吗?您是否阻止默认设置?