Why does this Python Flask router return a 400 error when pinged by a crossdomain AJAX call?
Question: I have the below Python Flask router:

    
    
    @app.route('/create', methods=['GET', 'POST'])
    @crossdomain(origin='*')
    def create():
        if request.method == 'POST':
            print(request.form)
            title = request.form['title']
            url = request.form['url']
    
            new_mark = Mark(
                title=title,
                url=url
            )
            new_mark.save()
    
            return new_mark
    

When I do an ajax call (below) it responds with a 400 error.

    
    
    $.ajax({
         type: 'POST',
         url: 'http://localhost:5000/create',
         data: {
                'title': sender.title,
                'url': sender.url
               },
         xhrFields: {
                withCredentials: true
               },
         dataType: 'json'
    });
    

When I try printing out `request` it prints an empty `immutableMultiDict`. Any
idea why it is giving this 400 and why there is no data?


Answer: Your ajax call is sending json-encoded data. I guess you should decode.

    
    
    import json
    
    data = json.loads(request.data)
    
    print data.get("title")
    

