So according to the jQuery Ajax docs, it serializes data in the form of a query string when sending requests, but setting processData:false
should allow me to send actual JSON in the body. Unfortunately I'm having a hard time determining first, if this is happening and 2nd what the object looks like that is being sent to the server. All I know is that the server is not parsing what I'm sending.
When using http client to post an object literal {someKey:'someData'}
, it works. But when using jQuery with data: {someKey:'someData'}
, it fails. Unfortunately when I analyze the request in Safari, it says the message payload is [object Object]
... great... and in Firefox the post is blank...
When logging the body content on the Java side it literally gets [object Object]
so how does one send REAL JSON data??
Has anyone had experience with a Java service serializing JSON data in the request body, with the request sent from jQuery?
BTW here is the full $.ajax request:
$.ajax({
contentType: 'application/json',
data: {
"command": "on"
},
dataType: 'json',
success: function(data){
app.log("device control succeeded");
},
error: function(){
app.log("Device control failed");
},
processData: false,
type: 'POST',
url: '/devices/{device_id}/control'
});
JSON.stringify()
? – Amathist