javascript - Network request error setTimeout$argument_0
问题描述
I'm using React Native and Node js to build an app.
When I try to send 'POST' request, I get an ERROR to the Command:
setTimeout$argument_0.
The full Error:
Network request failed
- node_modules\whatwg-fetch\dist\fetch.umd.js:527:17 in setTimeout$argument_0
- node_modules\react-native\Libraries\Core\Timers\JSTimers.js:135:14 in _callTimer
- node_modules\react-native\Libraries\Core\Timers\JSTimers.js:387:16 in callTimers
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:425:19 in __callFunction
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:112:6 in __guard$argument_0
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:373:10 in __guard
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:111:4 in callFunctionReturnFlushedQueue
- [native code]:null in callFunctionReturnFlushedQueue
The code:
fetch('myIP:3000/signup',
{
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
'email':values.email,
'password': values.password
})
})
.then(res=>{res.json()})
.then(data=>console.log('reach! ' + data))
.catch((err)=> console.log(err))
Edit: adding the fetch code
const { mongoURI } = require('./keys');
const express = require('express');
const mongoose = require('mongoose');
const User = require("./models/User");
const app = express();
const PORT = 3000;
app.use(express.json());
// database connection
mongoose.connect(mongoURI, { useNewUrlParser: true, useUnifiedTopology: true, useCreateIndex:true })
.then((result) => {app.listen(PORT); console.log('connected server ' + PORT)})
.catch((err) => console.log(err));
app.post('/signup', async (req, res) => {
const { email, password } = req.body;
try {
const user = await User.create({ email, password });
const token = createToken(user._id);
res.cookie('jwt', token, { httpOnly: true, maxAge: maxAge * 1000 });
res.status(201).json({ user: user._id });
}
catch(err) {
const errors = handleErrors(err);
res.status(400).json({ errors });
}
})
Anyone who knows how to solve that error?
解决方案
推荐阅读
- java - RxJava2 中 ConnectableObservable 的行为?
- python - Python:接受可迭代参数并生成元组的函数
- mysql - 构建此数据库的提示
- vba - 查找并替换具有相反值的特定列中的字符串,一次一行
- javascript - 如何在 Slick carousel 上制作黑色背景过渡?
- c# - Visual Studio 找不到 Microsoft.AspNetCore.DataProtection 的 PersistKeysToRedis 方法
- mysql - MySQL:仅选择仅具有某些值的组
- url-masking - 是否可以使用谷歌域来转发用端口屏蔽的子域并将其屏蔽?
- android - Android - ExpandableListView 内容在屏幕底部被截断
- r - 在 `dplyr` 的 `mutate()` 中应用函数