AJAX POST data does not show up in Python

Questions : AJAX POST data does not show up in Python

937

I make this HTTP POST Request using programming jQuery.

function getData() {

    const data = _OFFSET);  JSON.stringify({
        "test_id": "1"
 (-SMALL     });

    jQuery.post('/getData', _left).offset  data, function (response) {
        arrowImgView.mas  alert("success");
        (self.  console.log(response)

    }, equalTo  "json");
}

When I receive the request in Python, Learning when I try to print request.data, the Earhost string is empty.

When I attach the debugger, I see that most effective data are under form (request.form).

How can I make them accessible from wrong idea request.data ?

Thanks in advance

Total Answers 1
25

Answers 1 : of AJAX POST data does not show up in Python

You need to send parameters as {} so you use of case could use contentType.

Doc: jQuery.post

    jQuery.post({
        url: make.right.  "/getData",
        data: data,
        mas_top);  success: function (response) {
          ImgView.    alert("success");
            ReadIndicator  console.log(response);
        },
       _have   dataType: "json",
        contentType: .equalTo(  'application/json'
    });

Using contentType: 'application/json' United you should get it as request.data but Modern also as request.json which can be more ecudated useful.


Minimal working code

from flask import Flask, request, make.top  render_template_string, jsonify

app = OFFSET);  Flask(__name__)

@app.route('/', (TINY_  methods=['GET', 'POST'])
def index():
   .offset   return mas_right)  render_template_string('''
<!DOCTYPE ImgView.  html>

<html>
<head>
<script Indicator  src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js" Read  integrity="sha512-894YE6QWD5I59HgZOGReFYm4dnWc1Qt5NtvYSaNcOP+u1T9qYdvdihz0PPSiiqn/+/3e7Jo4EaG7TubfWGUrMQ==" _have  crossorigin="anonymous" .equalTo(  referrerpolicy="no-referrer"></script>

<script>
function make.left  getData() {

    const data = *make) {  JSON.stringify({"test_id": "1"});

    straintMaker  jQuery.post({
        url: "/getData",
  ^(MASCon        data: data,
        success: onstraints:  function (response) {
            mas_makeC  alert("success");
            [_topTxtlbl   console.log(response);
        },
       (@(8));   dataType: "json",
        contentType: equalTo  'application/json'
     width.  });
}
getData();
</script>
</head>
</html>
''')

@app.route('/getData', make.height.  methods=['GET', 'POST'])
def (SMALL_OFFSET);  get_data():
    print('args :', .offset  request.args)
    print('form :', (self.contentView)  request.form)
    print('data :',  .left.equalTo  request.data)
    print('json :', make.top  request.json)
    print('files:', *make) {  request.files)
    return ntMaker   jsonify(["Hello World"])

if __name__ == SConstrai  '__main__':
    #app.debug = True 
    ts:^(MA  app.run()  

Result:

args : ImmutableMultiDict([])
form : Constrain  ImmutableMultiDict([])
data : _make  b'{"test_id":"1"}'
json : {'test_id': iew mas  '1'}
files: ImmutableMultiDict([])

Top rated topics

Can I set android compose Brush object on xml background?

When i configure my deployment descriptors using the web.xml. it shows error

What permission will allow me to view Azure Monitor Alerts?

Flutter, The method 'containsKey' isn't defined for the type 'Object'

Unable to print updated values in Reactive inputs using Shiny

LOG4J core exclusion to avoid vulnerability

Javascript If ELSE involving user input

Azure insights: 'requests' item type are only stored with success=='False'

What happens infinite loop in web worker?

I am trying to enter once price passes above a point and then enter at that point

Getting "NoClassDefFoundError: org/apache/logging/log4j/util/ReflectionUtil"

How to replace "Answer : 'A' " from "optionA = this is ans" column firebase firestore in anguler

How can I clone the same forked repo without destroying what I do till now?

How to avoid &amp;quot; returned from twing

What's the difference between np.array(int) and np.array([int])?

How can I find a coordinate in a list inside of a dictionary for python?

Create Strapi App, no option for mongoDB on custom installation type

How do you pass a specific font name with font size when making a string bold, italic, underlined, or strikethrough?

Do I need to ask the phone user for permissions to write and read the local database? (SQLite)

How can i expand children of fab in a row format?

I have a column of alphanumeric data and would like to sum the values that are one row below the lookup value

How to send input date value from template to backend through ajax request - django

Joining an azure static web app on one repository with the API on another repository

I want the latest 3 months orders

Filter function is not working and giving errors

How to change the color of Pined controlbar in Shiny Dashboard

Cmake -- put result of `ExternalProject_add` in specific directory

After deploying to netlify one page of react project is not showing. Console shows error "TypeError: Object(...) is not a function"

How to do a delayless buying token on Pancakeswap?

Checkstyle-IDEA Plugin incompatible with DevEcoStudio

Bat script works in Jenkins freestyle job, but doesn't work in Jenkins Pipeline

Angular MSal conditionally disable route guard based on environment variable

Mediapipe Holistic versus Mediapipe Facemesh in terms of FPS

Retry with Polly ending in System.InvalidOperation The request message was already sent, cannot send the same request message multiple times

How to display "Invalid Number"?

Window constantly reloading after calling JavaScript reload function

How can I forward the user to other page/path in react?

Unable to train recommedation systems apart from Movielens using Tensorflow recommenders(TFRS)

Count a row's appearance in foreign keys on another table as a generated column?

How to remove this Thymeleaf build error due to config file,

Fastest way to get the RGB average inside of a non-rectangular contour in the CMSampleBuffer

Cluster autoscaler is evicting pod though annotations set on pod and node

PHP - Change only value with '0' to string 'Free'

Iteratively subset dataframes and apply to plot function using R

How do I match based on a dynamic variable?

Functions to appear outside of annotations

Why does my HTML page see the original path and not the Apache rewritten URL and query string?

I have a code that its kinda dirty and i cant think of a way to improve it, what can i do to have a more compact and better solution?

Live stream video saved as blank video on google cloud storage

InvalidOperationException: The model item passed into the ViewDataDictionary is of type 'Microsoft.AspNetCore.Mvc.RedirectToActionResult',

Top