Pass js object with ajax request
ajax, javascript, jquery, node.js
Solution
Try to use JSON.stringify
$.ajax({
data: JSON.stringify(data)
});
Problem
I need to send a js object to the server through ajax request; is an object containing parameters for a sql query with Sequelize orm in node js; an example is like this: ``` var data = { include: [ { model: model.Shop }, { model: model.Product, include: [ { model: model.File } ] } ] } ``` It can contain arrays of objects nested on multiple levels; before sending it I can convert it to valid JSON if needed, like this: ``` var data = { "include": [ { "model": "model.Shop" }, { "model": "model.Product", "include": [ { "model": "model.File" } ] } ] } ``` I've tried to send it as JSON: ``` $.ajax({ //... data: data }); ``` The problem is that when in the node server I do JSON.parse of the received string, the value of each property is a string and it is not recognized as a model object; How can I make my server able to understand this?