Ajax post data not as expected on server side (using Datatables ajax sourced tables)
Ajax post data not as expected on server side (using Datatables ajax sourced tables)
brodeurc
Posts: 3Questions: 1Answers: 0
Hi, i am trying to send a JSON structure to the server side (a JSON request) via AJAX but receives it as query params. With the example below i receive:
0=%7B&1=%22&2=s&3=e&4=r&5=v&6=i&7=c&8=e&9=%22&10=%3A&11=%22&12=j&13=s&14=o&15=n&16=-&17=s&18=u&19=b&20=j&21=e&22=c ....
code sample:
var request = {
service:"json-subject-service",
operation:"list-all",
sessionId:"dd"
};
var datab = JSON.stringify(request);
var table = $('#example').DataTable( {
ajax: {
type:'POST',
contentType:'application/json',
dataType:'json',
url:'service',
data: datab,
async:'false',
},
"columns": [
{"data": "uuid"},
{"data": "userName"},
{"data": "status"},
{ "defaultContent": "<button id=\"editButton\">edit</button>"}
]
} );
This discussion has been closed.
Answers
note: the query params structure is received in the input stream not in the url on the server side. i would expect to receive the "stringified" JSON string in the request input stream.
found this on the forum and it works BUT it would be better if we could prevent data from being posted as query params by using the "processData:false" in the ajax call (when using POST)
data: function ( json ) {
return JSON.stringify( json );
}
Im not sure why you have these parts in the
ajax
settings:I doubt they do anything, and if they did, you definitely wouldnt want the
async: false
in there.. (Especially since you pass a string instead of a boolean value..)