django js实现部分页面刷新
来源:互联网 发布:vim golang 插件 编辑:程序博客网 时间:2024/06/05 09:30
例子中,我用的是显示机器上的进程信息的表格,获取不同的机器的进程信息时,更新这个展示信息的表格,如下:
当我在输入框中输入ip时,我希望只是更新这个表格,页面其他部分不变,实现方式如下:
1、在原页面中设置这个表格的id为pstable
<table class="table table-striped" id="pstable"> <thead> <tr> <th>user</th> <th>pid</th> <th>cmd</th> </tr> </thead> <tbody> {% for ps in info.ps_data %} <tr> {% for item in ps %} <td>{{ item }}</td> {% endfor %} </tr> {% endfor %} </tbody> </table>
2、实现js
<script type="text/javascript">$(document).ready(function(){ $("#gobtn").click(function(){ var ip=$("#ip").val(); //获取输入框中的ip $.post("/process/",{'hostip':ip}, //post函数到后端 function(data,status){ //回调函数 $("#pstable").html(data); //将id为pstable的标签的html替换为返回的data $("#ip").val(ip) //将输入框的值改为查询的ip });});});
3、view函数
def process_view(request): hostip = request.POST.get('hostip') logger.debug("host:%s" % hostip) if hostip is None: ps_data = GetHostPs('192.168.163.128') info = {'username':request.user,'ps_data':ps_data} template = 'process.html' #return render(request,'process.html',{"info":info}) elif hostip: ps_data = GetHostPs(hostip) info = {'username':request.user,'ps_data':ps_data} template = 'pstable.html' #return render(request,'pstable.html',{"info":info}) else: ps_data = GetHostPs('192.168.163.128') info = {'username':request.user,'ps_data':ps_data} template = 'pstable.html' return render(request,template,{"info":info})
4、pstable.html 在这个html定义好要根据ip获取到进程信息后的html代码
<thead> <tr> <th>user</th> <th>pid</th> <th>cmd</th> </tr> </thead> <tbody> {% for ps in info.ps_data %} <tr> {% for item in ps %} <td>{{ item }}</td> {% endfor %} </tr> {% endfor %} <tbody>
当点击按钮查询指定ip的进程信息时,process()会判断这个ip的存在,如果这个ip存在,会将pstable.html保存到js函数中的data参数,然后js参数会调用回调函数,将id为pstable的tag的html替换为参数data保存的html,即pstable.html,从而局部修改页面,展示进程信息
5 0
- django js实现部分页面刷新
- django 用jquery ajax提交form 实现刷新部分页面
- django+js+ajax刷新页面
- django实现局部页面刷新
- js实现frame框架部分页面的刷新
- js实现页面刷新
- JS实现页面刷新
- js实现页面不停刷新
- js实现页面局部刷新
- 用iframe实现页面部分刷新
- JS 实现页面刷新的多种方法
- js实现页面定时跳转刷新【javascript】
- JS AJAX实现页面局部刷新~~~~
- JS AJAX实现页面局部刷新~~~~
- js实现frame框架页面刷新
- js实现让页面只刷新一次
- js实现父页面的刷新
- 页面禁止刷新处理Js实现
- (总结)Nginx配置文件nginx.conf中文详解
- obs nginx-rtmp-module搭建流媒体服务器实现直播 ding
- git push 出现unpacker error
- caffe-python apis
- Eclipse中创建新的Spring Boot项目(转载)
- django js实现部分页面刷新
- sql insert触发器遍历inserted表取数据操作
- html-webpack-plugin详解
- TLD目标跟踪算法学习(三)代码理解
- 微信小程序 video 安卓端可以播放 ios 端播放失败
- java中如何将office文件转成pdf或者图片(亲测有效)
- 深度学习笔记 (二) 在TensorFlow上训练一个多层卷积神经网络
- 对微服务和RESTful的理解
- 有关redis中setnx实现锁