小编M.S*_*lam的帖子

等待响应2分钟后的ajax net :: ERR_EMPTY_RESPONSE-node.js服务器

我有这段代码,其中客户端通过AJAX POST请求将文件上传到服务器,然后服务器将文件上传到云(云),并在上传完成后响应AJAX请求。

当文件上传花费的时间超过2分钟(我将它计时,因为从请求开始直到出现错误),就会发生问题。

如果上载时间少于2分钟,则一切工作正常,而上载时间超过2分钟的上载在发生错误后完全没有问题。但客户会在2分钟后收到空响应。

服务器端代码:

router.route('/posts').post(middleware.isLoggedIn, function (req, res) {
  var form = new multiparty.Form()
  form.parse(req, function (err, fields, files) {
    if (err) return err
    cloudinary.v2.uploader.upload(files.content[0].path, { resource_type: 
    'auto' }, function (err, result) {
      if (err) return err
      console.log(result)
      res.json({ result: result })
    })
})
Run Code Online (Sandbox Code Playgroud)

客户端代码:

function newPost (type, title, content) {
  if (type === 'image') {
    $('#newImageForm').addClass('loading')
  } else if (type === 'video') {
    $('#newVideoForm').addClass('loading')
  } else if (type === 'gif') {
    $('#newGifForm').addClass('loading')
  }
  var form = new FormData() …
Run Code Online (Sandbox Code Playgroud)

javascript ajax jquery httpresponse node.js

5
推荐指数
1
解决办法
1233
查看次数

标签 统计

ajax ×1

httpresponse ×1

javascript ×1

jquery ×1

node.js ×1