I have some javascript that should POST
json login data to a back end (using jquery).
var dataObj = {};
dataObj["email"] = email;
dataObj["password"] = password;
postdata = JSON.stringify(dataObj);
request.controllers.LoginController.login()
.ajax({
data: postdata
})
.then(function(data) { ...
The code above posts the following (with an incorrect colon at the end), and is posted as application/x-www-form-urlencoded
.
{"email":"myemail@example.com","password":"mypass"}:
It should be without the colon at the end, and be posted as application/json
.
Would like to know where my mistake is. If I specify the contentType and other things from "Send JSON data with jQuery", it makes no difference, so this is not a duplicate of that.
request.controllers.LoginController.login()
.ajax({
data: JSON.stringify(dataObj),
contentType: 'application/json; charset=utf-8',
dataType: 'json',
async: false,
processData: false
})
The problem is that when it gets to the ajax function it looks like this:
"{"email":"myemail@example.com","password":"mypass"}"