POSTing JSON data but need to manipulate data
POSTing JSON data but need to manipulate data
dshorthouse
Posts: 2Questions: 1Answers: 0
I am using CouchDB 2.1 and am trying to make use its built-in _find. This requires that I POST JSON data and so my ajax.data object is a function to return JSON.stringify. However, I also have a need to manipulate the data object just before POST using the preXhr.dt event. But, because the data object is now a string, I cannot manipulate it. Any suggestions?
This discussion has been closed.
Answers
Hi @dshorthouse ,
Can't you just cast it back to a JSON structure with
JSON.parse()
, do your manipulating, and then reconvert withJSON.stringify()
again?Cheers,
Colin
Thanks, @colin. Unfortunately, pre-/post-processing of data in $ajax DataTables assumes these are objects, not strings. I've had to hack the js file to get this to work & don't see how I can send a pull request for this because it would break the examples provided for POSTing JSON data, https://github.com/dshorthouse/orcid-taxonomist-couchdb/blob/master/public/js/jquery.dataTables.custom.js#L3937
The
preXhr
event happens after theajax.data
function is called. So if you need to manipulate the data before converting it to be a JSON string you would have to do it inside yourajax.data
function.Is that something that you can do?
Allan