Flask and Ajax Post requests 400

后端 未结 2 1890
长情又很酷
长情又很酷 2020-12-13 10:18

I am writing a small flask based site and I would like to send data from the client to the server using Ajax. Until now I have only used Ajax requests to retrieve data from

2条回答
  •  攒了一身酷
    2020-12-13 11:02

    Can you try like this

    var request = $.ajax({
        url: "/json_submit",
        type: "POST",
        contentType: "application/json",
        data: JSON.stringify({
          id: id, 
          known: is_known
        }),  
        dataType: "json",
      })  
       .done( function (request) {
     })
    

    Before that, In your code returns dict object. That is not correct. It returns json like

    @app.route("/json_submit", methods=["POST"])
    def submit_handler():
        # a = request.get_json(force=True)
        app.logger.log("json_submit")
        return flask.jsonify({'msg': 'success'})
    

提交回复
热议问题