// From AJAX you need to post the data as JSON string rather than
// a JavaScript object.
payload = JSON.stringify({"name": "foo", "username":"bar"})
$.ajax({
url: 'some url',
type: "POST",
// ...
data: payload,
dataType: 'json',
//..
})