I have the following JS Object:
json =
{
"category_id": category,
"subcategory_id": subcategory,
"offer_type": type_offer,
"features": []
};
I tried to send this object as JSON like:
$.ajax({
type: 'POST',
url: '/add',
data: json,
success: function (data) {
},
contentType: "application/json",
dataType: 'json'
});
Is it right? Or I need to make some preparations before?
Now I use this part of code:
formObj = $("#form_add").serialize();
var json = {};
var wrapperObj = {json: json, form: formObj};
$.ajax({
type: 'POST',
url: '/add',
data: JSON.stringify(wrapperObj),
success: function (data) {
// TODO
},
contentType: "application/json",
dataType: 'json'
});
Is it right way? When I package two object inside one and after stringify?