Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
156
rated 0 times [  160] [ 4]  / answers: 1 / hits: 21431  / 10 Years ago, fri, july 11, 2014, 12:00:00

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?


More From » jquery

 Answers
92

Try to use JSON.stringify



$.ajax({
data: JSON.stringify(data)
});

[#70239] Wednesday, July 9, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jaelyn

Total Points: 619
Total Questions: 102
Total Answers: 104

Location: Honduras
Member since Sun, Dec 26, 2021
2 Years ago
;