AJAX/PYTHON : how to send json value to server
<p>I am a new to Ajax/Python, I don't know how to POST a json value to my python server.</p>

<p>Python code: </p>

<pre><code>@app.route('/ajouterContact', methods = ['POST'])

    def ajouterContact():
        data = json.loads(request.data)
        #nom = request.form['nomContact'];
        contact.append(data)
        ajouter.make_response(json.dumps(contact), 201)
        ajouter.headers['Content-Type'] = 'application/json'
</code></pre>

<p>JS code</p>

<pre><code>$('#buttonAjouter').click(function() {
    var nom = 'Tom';
    var myObj = new Object();
    myObj.nom = nom;
    var jsonText =  JSON.stringify(myObj);

    var i = 0;
    $.ajax({
            url: '/ajouterContact',
            data: jsonText,
            type: 'POST',
            dataType: "json",
            success: function(response) {
                console.log(response);
            },
            error: function(error) {
                console.log(error);
            }
        });
});
</code></pre>

<p>I am getting this error on server side : </p>

<blockquote>
  <p>ValueError: No JSON object could be decoded</p>
</blockquote>

<p>If anyone can help me on this..<br>
Thank you!</p>

<p>You need to provide the contentType in your ajax request:</p>

<pre><code>contentType: 'application/json;charset=UTF-8',
</code></pre>

<p>Then in your server try to debug something like this:</p>

<pre><code>request.json
</code></pre>

python ajax