对于这里的大多数人来说,这个问题可能是基本的,但我真的厌倦了没有得到想要的 o/p。我想在单击列表中的项目(id = vzlabs_data)时进行 AJAX 调用,并且应在表中更新其各自的数据(id = table_data)。
目前,我能够发布数据,对它进行 db 调用,获取它的数据,并且获取的数据正在 python 解释器中打印,但不会在表中更新。
我哪里错了?
HTML 模板
<div class="navbar">
<div class="navbar-inner">
<ul class="nav" id="nav_bar">
<li class="active"><a href="#">Home</a>
</li>
<li><a href="#device">Device</a>
</li>
<li><a href="#content">Content</a>
</li>
<li><a href="#about">About</a>
</li>
<li><a href="#help">Help</a>
</li>
</ul>
</div>
</div>
<div class="pull-right">From :
<input type="text" id="from" name="from" />To :
<input type="text" id="to" name="to" />
</div>
<br>
<br>
<div class="container-fluid">
<div class="row-fluid">
<div class="span2 pull-left">//****** An item is picked up from this list**********
<ul class="nav nav-tabs nav-stacked"
id="vzlabs_data">
<li class="active"><a href="#">All Data</a>
</li>
<li><a href="#">VZW3RD</a>
</li>
<li><a href="#">VZWLAB</a>
</li>
<li><a href="#">VZW2ND</a>
</li>
</ul>
</div>
<!-- end of div span2-->
<div id="pie_chart" class="span4" style="height: 275px"></div>
<!-- end of div span4-->
<div class="span5">
<table class="table table-striped" id="table_data">
<thead>
<tr>
<th>Categories</th>
<th>Subscribers</th>
<th>Rate(bps)</th>
<th>Tonage(Bytes)</th>
</tr>
</thead>
<tbody>// Data is updated over here. {% for key, value in vzlab_data.items %}
<tr>
<td>{{key}}</td>
<td>{{value.subscriber}}</td>
<td>{{value.rate_bps}}</td>
<td>{{value.tonage_bytes}}
<div class="progress">
<div class="bar" style="width: 60%;"></div>
</div>
</td>
</tr>{%endfor%}</tbody>
</table>
</div>
<!-- end of div span7-->
</div>
<!-- end of div row-->
JS函数
$(function () {
$("#vzlabs_data li").click(function () {
$.ajax({
type: "POST",
url: "/dashboard/",
data: {
'lab': $(this).text()
},
success: function (result) {
$("#table_data").html(result);
}
});
});
});
视图.py
def dashboard(request):
vzlab_data = get_vzlab_data("All Data")
if request.is_ajax():
lab = request.POST['lab']
vzlab_data = get_vzlab_data(lab)
return HttpResponse(simplejson.dumps(vzlab_data), mimetype='application/javascript')
ctx = {'vzlab_data' : vzlab_data}
return render_to_response('dashboard/dashboard1.html',ctx, context_instance = RequestContext(request))