为什么浏览器返回意外的input结束时,我可以从浏览器获取API响应?
我有一个非常基本的反应前端和一个非常基本的nodejs服务器。
我试图validation服务器上的用户名和密码,当客户端点击提交,然后最终redirect到他们的仪表板。 现在我无法发送用户数据请求了。
这是我在服务器上非常基本的身份validationfunction,身份validation和searchusers等function不是asynchronous的。
// Authorization app.get('/auth/:userId/:hash', function(req, res){ var id = req.params.userId.toString(); var hash = req.params.hash.toString(); var error = { err: 'something went wrong!' } var user = dm.searchUser(id, users); if (!user){ res.json(error); } var isAuthenticated = dm.authenticate(user, hash); if (!isAuthenticated){ res.json(error); } if(isAuthenticated){ console.log('authed') res.json(user); } });
这是处理表单提交行为的客户端反应组件方法。
submit(e){ e.preventDefault(); const BASE_URL = "http://localhost:3001/auth/" fetch(`${BASE_URL}${this.state.userId}/${this.state.password}`, { method: 'GET', mode: 'no-cors' }) .then(response=>response.json()) .then(json=>{console.log(json)}) .catch((err)=>{ console.log(err) }) }
从我所尝试的,如果我试图从我的浏览器发送请求,服务器确实响应我的JSON数据。
但是当我试图对我的客户做同样的事情时,它会给出一个错误,有人可以帮我解决问题吗?
[编辑]
这是我得到的错误