I am developing the web using google app engine. I used jinja2 to send data from html to main. pays code. The problem is how to get the data from the javascript of html. Please let me know the correct answer. Thank you.
main.py
def get(self):
db = connect_to_cloudsql()
cursor = db.cursor()
cursor.execute("set names utf8")
cursor.execute("""select no, u_name, age, gender, U_adress, phone, car_num, penalty from User;""")
data = cursor.fetchall()
array_list = []
for row in data:
temp = (row[0], str(row[1]), row[2], str(row[3]), str(row[4]), row[5], str(row[6]), row[7])
array_list.append(temp)
db.close()
data = json.dumps(array_list)
template_values = { 'data': data }
template = JINJA_ENVIRONMENT.get_template('User.html')
self.response.write(template.render(template_values))
and javascript code in html.
var table;
$(function() {
$.get(function({ data }) {
var jsonobj = JSON.parse({ data });
table = $('#userindex').dataTable({
"sPaginationType": "bootstrap",
"sDom": "t<'row'<'col-xs-6 col-left'i><'col-xs-6 col-right'p>>",
"bStateSave": false
});
$.each(jsonobj, function(key,value) {
table.fnAddData(
value[0],
value[1],
value[2],
value[3],
value[4],
value[5],
value[6],
value[8]
);
});
});
});
this is my error
datatables.min.js:16 GET https://firststep-2016.appspot.com/function%20(%7Bdata%7D)%7Bvar%20jsonobj%20=%20JSON.parse(%7Bdata%7D);table%20=%20$(' 404 ()