how can I use data posted from ajax in flask?

后端 未结 4 1345
后悔当初
后悔当初 2020-11-28 02:30

I\'m having trouble getting data POSTed from jquery ajax.

$(\'#clickme\').click( function() {
    var data = save_input(); // data

    data[\'_sid\'] = $sur         


        
4条回答
  •  囚心锁ツ
    2020-11-28 03:08

    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

提交回复
热议问题