I tried to merge two json both with $.extend
and $.merge
but no success. I also tried to attach it like this:
data: JSON.stringify({"data" : [
{term: request.term},
jsontag
]}),
Here's my setup:
autocomplete: ({
source: function (request, response) {
var tags = $('#input-newsearch-2').val();
var jsonfied = {
tags: tags.replace(/,$/, "").split(",").map(function (tag) {
return { tag: tag };
})
};
var jsontag = JSON.stringify(jsonfied);
var jsonterm = JSON.stringify({ term: request.term });
//console.log(jsontag);
//console.log(jsonterm);
//var mergedObj = $.extend(jsontag, jsonterm);
//console.log(mergedObj);
$.ajax({
url: "/source",
type: "POST",
contentType: "application/json; charset=utf-8",
dataType: "json",
data: [jsontag, jsonterm],
success: function (data) {
response(data);
}
});
},
});
Console:
{"tags":[{"tag":"value01"},{"tag":"value02"},{"tag":"value03"}]}
{"term":"value04"}
I was hoping to get sth like:
[{"term":"value04"},{"tags":[{"tag":"value01"},{"tag":"value02"},{"tag":"value03"}]}]
Or even better:
{"data":[{"term":"value04"},{"tags":[{"tag":"value01"},{"tag":"value02"},{"tag":"value03"}]}]}