0

I want to get the "Data" list passed from my javascript to python FLASK APP and than work on the list "Data" JavaScript code to send is

function fetch()
    {
     var jsonObj={'email':"[email protected]",'Data': ['Name','Phone']};
      $.ajax({
                 url:'http://192.168.56.102:5000/fetch',
                 data:jsonObj,
                 type:"POST",
                 dataType:"json",
                 crossDomain:true
             }).done(function(result){console.log(result)}).fail(function(result){console.log("error")});
    }

The Python FLASK code is

@app.route("/fetch", methods=["POST"])
def fetch():
    print request.json
    return jsonify({"Status":200})

from the print statement above I get

ImmutableMultiDict([('Data[]', u'Name'), ('Data[]', u'Phone'), ('email', u'[email protected]')])

But I want to get something like this

ImmutableMultiDict( { 'email': '[email protected]', 'Data' : ['Name','Email'] } )

In short I want to get the list in server side so send by JSON.

PS : I have already tried How to get a JSON Object in Python (Flask Framework) but on implementing this I am getting

ImmutableMultiDict([])

0

1 Answer 1

1

You need to convert the data to JSON yourself, and use contentType to set the content-type header.

$.ajax({
   url:'http://192.168.56.102:5000/fetch',
   data: JSON.stringify(jsonObj),
   type:"POST",
   contentType:"application/json",
   ...
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.