solved. The solution is to set the contentType to "application / json" and use JSON.stringify (obj) instead of obj, but you may need to change the way you receive data on your server depending on the language or structure. Original question below ...
This is what i am trying
var obj = {
'firstName': 'bill',
'lastName': 'johnson',
'hobbies': ['apples', 'dogs']
});
$.ajax({
type: 'POST',
url: '/myurl'
data: obj,
success: function(data){alert(data);}
});
If I warn / write a JSON.stringify(obj), I get the correct result, that is:
{'firstName': 'bill', 'lastName': 'johnson', 'hobbies': ['apples', 'dogs']}
However, when I make the above ajax call, my server receives the following:
{'firstName': 'bill', 'lastName': 'johnson', 'hobbies[]': 'apples'}
Which is clearly not correct json. I tried to add various arguments contentType, but then my server actually received nothing (empty mail request).
JSON ( ), jquery , :
{"{\"firstName\":\"bill\",\"lastName\":\"johnson\",\"hobbies\":[\"apples\",\"dogs\"]}": ""}
processData false .
. , json ...
?