Answer the question
In order to leave comments, you need to log in
How to pass large JSON via $.ajax and not get Request entity too large?
I am writing a small web application using Node.js + Express + jQuery.
I have a server that sends a JSON document to the client via GET. On the client, this document is edited and sent via POST back to the server.
And when the document is transferred to the server, only 1.4 kB is transferred, and the server answers me Request entity too large.
Part of the server code:
// ...
app.use(bodyParser.json());
// ...
app.post('/post_data', function(req, res) {
console.log(req);
});
// ...
$.ajax({
url: '/post_data',
type: 'POST',
dataType: 'json',
contentType: 'application/json',
data: {translated:JSON.stringify(data)},
success: function (res) {
console.log('save');
}
});
app.use(bodyParser.json({limits: '50mb'}));
Answer the question
In order to leave comments, you need to log in
You need to add processData: false, and pass the request body as a string. bodyParser.json() treats the entire request body as a JSON document, not as form data.
ajax.json({
// ...
processData: false,
data: JSON.stringify(data)
// ...
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question