Below is my flask view:
import db_connect_test
from db_connect_test import Viz_Connector
from flask import Flask, request, session, redirect, url_for, render_template, flash,json,jsonify
import os
app = Flask(__name__)
@app.route('/',methods = ['GET','POST'])
def select_ID():
if request.method == 'POST':
ID=request.form['input_ID']
Node_type = request.form['Node_Type']
data = Viz_Connector(ID,Node_type).get_data()
if data == 'Wrong ID and Node_type':
return data
else:
return json.dumps(data)
return render_template('dropdown.html')
When data does not exist in the back end application database, the method:
Viz_Connector(ID,Node_type).get_data()
returns 'Wrong ID and Node_type'
Below is my ajax/query:
$('input[type=submit]').click(function() {
var input_ID = $("#input_ID").val();
var Node_Type = $("#Node_Type").val();
$.ajax({
type: "POST",
url: "/",
dataType: 'json',
data: {
input_ID: input_ID,
Node_Type: Node_Type,
},
success: function(data) {
if (data == 'Wrong ID and Node_type') {
alert(data);
} else {
var IDData = JSON.stringify(data); //--data getting passed from flask view when ID and node_type exist
console.log(IDData);
---code to render graph---
}
});
return false;
)}
When the ID and Node_type exist in the database everything works fine and the else part of both the Flask view and Ajax/jquery works and graphs get displayed.
When they are not found though, the alert piece does not work and no alert pops up.
Unable to figure out if anything is missing.