I have created a python flask web-server that as of now just needs to print the data it receives to the screen. I am using HTML/javascript to make a webpage with a button. When the button is pressed, the JS should send a HTTP post request to the python server using AJAX. I got the webpage and the server to connect (I know because i am receiving a 200 code rather than a 'no JSON object' error), but the server does not appear to receive the post request. Instead, it responds with HTTP 200 OPTIONS. What do i need to do to send the json object to the server?
here is the webserver:
from random import randint
import time
import datetime
import json
import decimal
from flask import Flask, jsonify, abort, request, make_response, url_for
app = Flask(__name__, static_url_path="")
#standard error handlers
@app.errorhandler(400)
def bad_request(error):
    return make_response(jsonify({'error': 'Bad request'}), 400)
@app.errorhandler(404)
def not_found(error):
    return make_response(jsonify({'error': 'Not found'}), 404)
@app.route('/api/data', methods=['POST'])
def post_data():
    data = json.loads(request.data)        
    print data
    print 'here'
    return jsonify({'result': 'true'}), 201
if __name__ == '__main__':
    app.run(debug=True)
here is the simple webpage:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<title>My jQuery JSON Web Page</title>
<head>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript">
JSONTest = function() {
    var resultDiv = $("#resultDivContainer");
    $.ajax({
        url: "http://localhost:5000/api/data",
        type: "POST",
        dataType: "json",
        contentType: 'application/json; charset=utf-8',
        data: JSON.stringify({apiKey: "23462"}),
        success: function (result) {
            switch (result) {
                case true:
                    processResponse(result);
                    break;
                default:
                    resultDiv.html(result);
            }
        },
        error: function (xhr, ajaxOptions, thrownError) {
        alert(xhr.status);
        alert(thrownError);
        }
    });
};
</script>
</head>
<body>
<h1>My jQuery JSON Web Page</h1>
<div id="resultDivContainer"></div>
<button type="button" onclick="JSONTest()">JSON</button>
</body>
</html> 
 
    