I am creating a web page that sends an XHR AJAX request using jQuery's $.post() object. The post is being received by a Flask app that is on another domain. The Javascript is below:
$.post('http://myurl.com/create', {
'title': sender.title,
'url': sender.url
});
The applicable Flask router code is:
@app.route('/create', methods=['GET', 'POST'])
@crossdomain(origin='*')
def create():
print(request.args.get('title'))
if request.method == 'POST':
title = request.form['title']
url = request.form['url']
new_mark = Mark(
title=title,
url=url
)
new_mark.save()
return redirect(url_for('index'))
The Python is working great when a form is submitted to the url, but not when I POST through jQuery's AJAX object. It throws a 400 error every time I try to make the AJAX request. I looked at Flask's request.args object, but that has nothing in it when the request is made.
Any ideas?