Flask Python, trying to return list or dict to Ajax call
Flask doesn't expect that you will return list
object from your view function. Try jsonify
it before:
from flask import jsonify@bookings.route( '/get_customer', methods=[ 'POST' ] )def get_customer(): name = {} for key, value in request.form.items(): name[ key ] = value customer_obj = customer_class.Customer() results = customer_obj.search_customer( name ) return jsonify(customers=results)
josonify works..but if you intend to just pass an array without the 'results' key, you can use json library from python. The following conversion works for me..
import json @app.route('/test/json') def test_json(): list = [ {'a': 1, 'b': 2}, {'a': 5, 'b': 10} ] return json.dumps(list)
You need to do
return jsonify(result=your_result)
Also check documentation which could be really helpful.