weixin_33721427 2017-06-04 16:39 采纳率: 0%
浏览 91

Flask Ajax Modal

I want to load a page with Bootstrap modal using ajax. Scenario is like,

  1. When a button is clicked,
  2. The button will call ajax to get data,
  3. From flask, it will get related data from DB and return the data in JSON format,
  4. In ajax success part, it will dynamically generate modal page and show it up.

I wasn't able to find a good example and I'm getting errors even returning html page.

My sample code runs on

<html>
<head>
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<link rel="stylesheet" href="../static/css/jquery.modal.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.6/js/bootstrap.min.js"></script>
<script src="../static/js/jquery.modal.min.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
// Open modal in AJAX callback
$('#manual-ajax').click(function(event) {
  event.preventDefault();
  $.get(this.href, function(html) {
    $(html).appendTo('body').modal();
  });
});
</script>
</head>
<main>
<a href="/ajax2" id="manual-ajax">second example</a>
</main>
</html>

and flask part will return

@app.route('/ajax2')
def ajax2():
  return app.send_static_file(url_for('static', filename='../templates/ajax2.html'))

but it generates 404 error even from beginning. Please help.

  • 写回答

1条回答 默认 最新

  • lrony* 2017-06-04 17:03
    关注

    You can write: $('id_body_modal').html(html); $('id_modal').modal('show');

    评论

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效