Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
363 views
in Technique[技术] by (71.8m points)

javascript - 提取信息时数据到达未定义(Data arrives undefined when Fetching a post)

So I tried to make a registeration form that post Username, password and email adress to my ExpressJs Server and save it, but The Object arrives undefined... here is my JS code in my react app.:(因此,我试图制作一个注册表单,将用户名,密码和电子邮件地址发布到我的ExpressJs Server上并保存,但是对象未定义到达...这是我的react应用程序中的JS代码。)

let RegDetails = { userName: userName, password: password, email: email } let regJSONED = JSON.stringify(RegDetails); fetch('http://localhost:4000/users/register', { method: 'POST', Headers:{ "Content-Type": "application/json" }, body: {regJSONED}, }).then(data => console.log(data)); I'm pretty sure the error is in this code, because when I'm posting with Postman on JSON format the body is arrving as it supposed, but with this fetching the body is arriving like this:(我很确定错误是在此代码中,因为当我以JSON格式与Postman一起发布时,主体正在按预期的方式到达,但是通过这种方式获取主体将像这样到达:) { userName: undefined, password: undefined, email: undefined } Can someone help me detect the error?(有人可以帮助我检测到错误吗?)   ask by SahiBalata translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

Please log in or register to reply this article.

OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...