I need to perform an AJAX call to send some JSON object to a server
$.ajax({
url: serviceURL+'stores/'+store_id+'/karaoke/song/new',
type: "POST",
contentType: "application/json; charset=utf-8",
data: { song: id, date: "date", user: "test", help: false, partners: [], likes: 0 },
dataType: "json"
});
that's what i got, I used wireshark to log what i was sending and what i was sending was this
JavaScript Object Notation: application/json
Line-based text data: application/json
song=name&date=date&user="test"&help=false&partners=[]&likes=0
How could that call, with the specified dataType and contentType could transform a JSON into line based text data, how can i send the JSON object instead
You can use the Json2 library to convert the json to a string before it is sent. Once it reaches the server it will be parsed.
var song = { song: id, date: "date", user: "test", help: false, partners: [], likes: 0 }
var json = JSON.stringify(song)
$.ajax({
url: serviceURL+'stores/'+store_id+'/karaoke/song/new',
type: "POST",
contentType: "application/json; charset=utf-8",
data: json,
dataType: "json"
});