国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

Django+Ajax+jQuery實現網頁動態更新

2019-11-10 18:41:24
字體:
來源:轉載
供稿:網友

views.py中的修改

增加相應的請求處理函數:

def getdevjson(request):    

返回字符串中,既可以使用from django.http import JsonResponse,也可以使用HttpResponse(json.dumps(res))

前端網頁修改

<script type="text/javascript">    window.jQuery || document.write("<script src='../static/js/jquery.min.js'>" + "<" + "/script>");</script><script type="text/Javascript">  $(function() {        var submit_form = function(e) {	 $.Ajax({            type : "GET",            url : "/getdevjson?"+Math.random(),            data : {                key: $('#searchContent').val()            },            dataType : "text",            success : function(res){			$('#searchContent').focus().select();			//console.log(res);            update(res);		 },			error : function() {                alert("處理異常返回!");}     		      });	          return false;    };    $('#calculate').bind('click', submit_form);    $('input[type=text]').bind('keydown', function(e) {      if (e.keyCode == 13) {        submit_form(e);      }    });    $('#searchContent').focus();  });</script>

<div class="divRight" id="divright1"> <div class="divRight" style="height:70px; width:370px;"><label id="lblSearch" class="CSSLabelSearch">請輸入查詢key:</label><input id="searchContent" type="text" size="40"></input> <input id="calculate" type="button" value="確定" ></input></div>  <br><label id="lbl1" class="cssLabelClient">節點信息</label><Textarea id="ClientInfoArea" readonly class="txtClientInfo"></Textarea></div>

#calculate是一個按鈕,點擊動作綁定了提交函數submit_form,ajax的請求參數中,data中包含了查詢參數,success是請求成功后的動作,注意返回的res需要進行json解析才可以正確使用:root = JSON.parse(jsondata);update(res)是一個更新網頁內容的函數

路由配置修改

urls.py中修改如下:

from django.conf.urls import patterns, include, urlfrom django.contrib import adminadmin.autodiscover()urlpatterns = patterns('',    url(r'^getdevjson$','dev.views.getdevjson',name='getdevjson'),    url(r'^','dev.views.index',name='index'),        url(r'^admin/', include(admin.site.urls)),)需要注意的是為了避免路由被覆蓋,將index的路由配置盡量放置在最后一行。


上一篇:DP紫書匯總

下一篇:poj1528

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 香格里拉县| 威宁| 禹城市| 博白县| 合江县| 子洲县| 漳州市| 南涧| 瑞丽市| 莲花县| 潮安县| 海淀区| 嘉兴市| 板桥市| 开阳县| 湘潭县| 抚顺市| 论坛| 防城港市| 邹平县| 盐池县| 西充县| 磐石市| 镇安县| 大姚县| 富锦市| 罗定市| 观塘区| 嵊泗县| 高州市| 日喀则市| 灵寿县| 正蓝旗| 缙云县| 隆昌县| 遵义县| 黔西| 从化市| 石狮市| 昌平区| 金堂县|