Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/422.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 网络请求错误setTimeout$参数\u 0_Javascript_Node.js_React Native_Fetch - Fatal编程技术网

Javascript 网络请求错误setTimeout$参数\u 0

Javascript 网络请求错误setTimeout$参数\u 0,javascript,node.js,react-native,fetch,Javascript,Node.js,React Native,Fetch,我正在使用React Native和Node js构建一个应用程序 当我尝试发送“POST”请求时,命令出错: setTimeout$argument\u 0 完整错误: 网络请求失败 setTimeout$argument\u 0中的node\u modules\whatwg fetch\dist\fetch.umd.js:527:17 node\u modules\react native\Libraries\Core\Timers\JSTimers.js:135:14 in\u call

我正在使用React Native和Node js构建一个应用程序

当我尝试发送“POST”请求时,命令出错:

setTimeout$argument\u 0

完整错误:

网络请求失败

  • setTimeout$argument\u 0中的node\u modules\whatwg fetch\dist\fetch.umd.js:527:17
  • node\u modules\react native\Libraries\Core\Timers\JSTimers.js:135:14 in\u callTimer
  • callTimers中的节点\u modules\react native\Libraries\Core\Timers\JSTimers.js:387:16
  • 调用函数中的节点\u modules\react native\Libraries\BatchedBridge\MessageQueue.js:425:19
  • 节点\u modules\react native\Libraries\BatchedBridge\MessageQueue.js:112:6位于\uuuu-guard$argument\u 0中
  • 保护中的节点\u模块\react native\Libraries\BatchedBridge\MessageQueue.js:373:10
  • callFunctionReturnFlushedQueue中的节点\模块\react native\Libraries\BatchedBridge\MessageQueue.js:111:4
  • [本机代码]:callFunctionReturnFlushedQueue中为null
守则:

    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))
编辑:添加获取代码

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 });
  }
})

有人知道如何解决这个错误吗?

您是如何处理响应的?包括你的代码。你的NodeJS服务器上有错误吗?NodeJS服务器上没有错误,我只是简单地处理响应:app.post('/signup',(req,res)=>{res.send('got post request');console.log('got post request');}现在只是想在两者之间交流…发布完整的获取代码编辑并添加完整代码:)实际上我想要获取代码。那么顶部的代码在fetch调用之后会发生什么呢?