Am using a script to make a simple post request to my Django backend. I want the data to be in Json format.
<input id ="my" type="submit" onclick="me()"/>
<script>
function me()
{
var data2 =JSON.stringify ({
"crave": "romana",
"uid": "100",
"access_token": "AAA"
});
alert(data2);
$.ajax({
url: "http://localhost:8000/trial/",
type: 'POST',
contentType: "application/x-www-form-urlencoded",
data: data2,
dataType: 'json',
processData: false
});
}
</script>
In the view when i print request.POST it shows the following
{u'{"crave":"romana","uid":"100","access_token":"AAA"}': [u'']}
enter code here
What am I doing wrong?
Try the following:
Or as a shortcut: