Making a ajax POST from a User Agent
$.ajax({
type: 'POST',
url: 'https://mysub.domain.dev/myroute',
headers: {
'X-Requested-With': 'XMLHttpRequest'
},
contentType: 'application/octet-stream; charset=utf-8',
success: function(result) {
successAction();
},
processData: false,
data: myResult['myValue']
});
With Koa2 on my server, how do I get the data myResult['myValue'] from the POST body?
const bodyParser = require('koa-body');
const router = new Router();
const body = bodyParser();
router.post('/myroute/', body, async (ctx, next) => {
const getMyValue = ctx.request.body.data.myValue;
}
I've tried various combinations. All are undefined or empty objects.
const getMyValue = ctx.request.body
Object{}
const getMyValue = ctx.request.body.data;
undefined
const getMyValue = ctx.request.body.myResult['myValue'];
undefined