I want to pass the selected value from dropdown which contains names of databases and pass it to the python script in the background which connects to the passed database name. Following is the ajax code that i have written
<script type="text/javascript">$(document).ready(function(){$("button").click(function(){$.ajax({url : "/form_submit",data : $('#databases').val(),type : 'POST',success : alert("Hi dear count " + $('#databases').val())});});});
</script>
The "databases" is the id of the select tag in HTML. I am writing data :
$('#databases').val()
to pass the data to the python code.
Following is the python code which should accept the passed value. If i run the below code directly from console, then it returns the result in json format but running it indirectly has not succeeded
@app.route("/form_submit/", methods=['GET','POST'])
def connect():import jsondtb = request.select['value']db = MySQLdb.connect("localhost","root","",dtb)cursor = db.cursor()cursor.execute("SELECT * FROM REPORT_SUITE")results = cursor.fetchall() json_return_value =[]for result in results:table_data = {'REPORTSUITE_ID' : result[0], 'REPORTSUITE_NAME' : result[1], 'STAGING_DATABASE' : result[2], 'DWH_DATABASE' : result[3], 'TRANS_TABLE' : result[4]}json_return_value.append(table_data)print ("hi")print json.dumps(json_return_value)return json.dumps(json_return_value)
I have declared the variable as dtb = request.select['value']
which should accept the database name passed through AJAX call.
Also i should be able to see the returned data in JSON format in my web browser.
I have looked around and applied many suggested solutions but i still am unable to determine how to pass and catch the passed value.