You are not sending JSON; you are sending a regular application/x-www-form-urlencoded
request instead. A X-WWW-Form-URLEncoded POST body uses URL percent encoding; spaces are encoded as +
characters in that encoding.
jQuery does this because data
is not already a string. You must encode the data to a JSON yourself:
$.ajax({
type: postMethod,
url: url,
cache: false,
data: JSON.stringify({'params': params}),
contentType: "application/json",
dataType: 'JSON',
statusCode: {
200: function (data, textStatus, jqXHR) {
//console.log('200');
callback(data);
},
201: function (data, textStatus, jqXHR) {
//console.log('201');
callback(data);
},
400: function (data, textStatus, jqXHR) {
//console.log('400');
callback(data);
}
}
});
Setting the correct content type for the data you send is always a good idea.
Setting the dataType
argument only matters for the response, telling jQuery
to decode the data received as JSON. It has no bearing on how data
is sent to the server.
It looks as if you are using Pyramid for the Python side; you want to use Request.json_body
to access the JSON-encoded data as a Python object.