how can I use data posted from ajax in flask?

Try

 $.ajax({
    type : "POST",
    url : "{{ url_for('mod.load_ajax') }}",
    data: JSON.stringify(data, null, '\t'),
    contentType: 'application/json;charset=UTF-8',
    success: function(result) {
        console.log(result);
    }
});

Then from the server, you can refer to the variables in data like this :

request.json['foo']

Since the content type is specified as application/json the data is in request.json

Leave a Comment