如何在python中的同一页面上显示显示的db.query搜索结果



我有一个html页面(searchCustomer.html(,它有一个输入字段,我们在其中输入要在数据库中搜索的字符串,点击搜索按钮后,记录被成功提取,并以html显示。当在同一页面(searchCustomer.html(中单击第一列(href(时,我想显示从html中单击的记录的详细信息

<form action="/getsearchresults" method="post">
<!-- <form action="/getsearchresults" method=  methods=['GET', 'POST'] > -->
<Text  text="Customer Name" id="text0"/>
<Input width="200px"  name="custName"  required  placeholder="Please enter the customer name"/>
<button type="submit">Search Customer</button>
<button  id="#btnID">TEst Customer</button>

</form>
<table border="1">
<tr><td><strong>Customer Id</strong></td><td><strong>Name</strong></td></tr>
{% for name1 in customers %}
<tr><td><a href="/DispCustomerInfo?query={{ name1.name }}">{{name1.id}}</a></td><td>{{name1.name}} 
</td></tr>
{% endfor %}
</table>

单击href,我想在同一页中显示该记录的详细信息

这里有一个可能的解决方案

from flask import request, jsonify
@app.route('/DispCustomerInfo')
def get_customer_info():
name = request.args.get('query', False)
customer = {}
if name:
#1 Query database
#2 Assign result to customer
return jsonify(customer)

在前端,使用Ajax获取客户数据。

<td><a class="customername" href="#" data-name="{{ name1.name }}">{{name1.id}}</a></td>
$( document ).ready(function() {
$(".customername").on('click', function(){
var name = $(this).data('name');
$.get("/getReport", {'query': name}).done(function (data) {
// Use jquery to append customer data to a DOM element.
});
});
});

最新更新