首页 > 解决方案 > Ajax POST 413 负载太大 NodeJs + Express 4>

问题描述

我的 Ajax POST 抛出错误 413 Payload Too Large。我在我的 nodejs 代码中尝试了以下解决方案:

"use strict";
var bodyParser = require('body-parser');
var express = require('express');  
var jsonParser = bodyParser.json();

var workspace = (app, dbconn)=>{
  app.use( bodyParser.json({limit: '50mb'}) );
  app.use(bodyParser.urlencoded({
  limit: '50mb',
  extended: true,
  parameterLimit:50000
  }));
}

但这仍然抛出错误。

我的ajax调用如下:

 $.ajax({
    url: "/private/save_ws",
    type: 'post',
    headers: {'x-secure':_user_token, 'x-user':_user_name},
    contentType: 'application/json',       
    dataType: 'json',            
    data: widget_data
}).done(function(response){
    console.log('success');
}).fail(function(data){
    console.log('FAILED! ERROR: ');
});    

标签: javascriptnode.jsexpress

解决方案


推荐阅读