Привет, я использую колбу для создания веб-приложения на python.На моей странице profile.html в директории шаблонов у меня есть profile.html, как показано ниже.
<!DOCTYPE html>
<html lang="en">
<head>
<title>App</title>
<link href="http://getbootstrap.com/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="http://getbootstrap.com/examples/jumbotron-narrow/jumbotron-narrow.css" rel="stylesheet">
<script src="../static/js/jquery-1.11.2.js"></script>
<script src="../static/js/getAcademic.js"></script>
</head>
<body>
<div class="jumbotron">
</div>
</body>
</html>
В app.py,
@app.route('/getDetails')
def getDetails():
try:
#get data from mysql database and convert to a json and return
return json.dumps(academic_dict)
except Exception as e:
return render_template('error.html', error=str(e))
Возвращенный объект json выглядит следующим образом:
В моем файле js
$(function() {
$.ajax({
url: '/getDetails',
type: 'GET',
success: function(res) {
var div = $('<table>')
.attr('class', 'list-group')
.append($('<tr>')
.attr('class', 'list-group-item active')
.append($('<td>')
.attr('class', 'list-group-item-text'),
$('<td>')
.attr('class', 'list-group-item-text')));
var wishObj = JSON.parse(res);
var wish = '';
$.each(wishObj,function(index, value){
wish = $(table).clone();
$(wish).find('td').text(value.Title);
$(wish).find('td').text(value.Data);
$('.jumbotron').append(wish);
});
},
error: function(error) {
console.log(error);
}
});
});
json преобразуется и возвращается правильно, но данные не отображаются в профиле.html страница.Я проверил консоль, и она отображает ошибку Uncaught ReferenceError: table is not defined
в файле .js.
Я хочу отобразить таблицу с данными, возвращенными в качестве объекта json, но таблица не отображается, когда profile.htmlстраница загружается.Пожалуйста, помогите мне с этим.