HTML 片段:
由于服务端返回的数据格式是HTML片段,因此并不需要经过处理就可以将新的HTML数据插入到主页面中。jQuery代码如下:
HTML 片段实现起来只需要很少的工作量,但这种固定的数据结构并不一定能够在其他的Web应用程序中得到重用。
def testjquery(req):
print req.get_full_path()
print req.GET['username'];
print req.GET['content'];
d=[]
d.append(req.GET['username'])
d.append(req.GET['content'])
print type(d)
print d
return HttpResponse( req.GET['username'] + req.GET['content'])
return render(req,'cmdb/modifyBtn.html',{'info':info})
def testjquery(req):
print req.get_full_path()
print req.GET['username'];
print req.GET['content'];
d=[]
d.append(req.GET['username'])
d.append(req.GET['content'])
print type(d)
print d
return render(req,'testjquery.html',{'info':d})
[22/Jan/2018 12:52:54] "GET /testjquery/?username=123&content=789 HTTP/1.1" 200 614
/testjquery/?username=123&content=789
123
789
<type 'list'>
[u'123', u'789']
[22/Jan/2018 12:52:55] "GET /testjquery/?username=123&content=789 HTTP/1.1" 200 614
将数组分配给前台页面
{% for x in info %}
<label class="condition">地址</label><input type="text" name="ip" class="equipment_sz" value={{x.0}}>
<label class="condition">描述</label><input type="text" name="info" class="equipment_sz" value={{x.1}}>
node2:/django/mysite/news/templates#cat testjquery.html
<form id="condition" action="/static/modifyEquipment" method="post">
{% for x in info %}
<label class="condition">值</label><input type="text" name="ip" class="equipment_sz" value={{x}}>
<input type="submit" value="设备修改" class="equipment_add_btn">
{% endfor %}
</form>
node2:/django/mysite/static/Js/Monitor#cat a32.js
$(function(){
$("#send").click(function(){
$.get("/testjquery/",{
username : $("#username").val(),
content:$("#content").val()
},function (data,textStatus){
console.log(data);
console.log(textStatus);
$("#resText").html(data);
});
})
})
此时返回的是HTML:
<form id="condition" action="/static/modifyEquipment" method="post">
<label class="condition">值</label><input type="text" name="ip" class="equipment_sz" value=123>
<label class="condition">值</label><input type="text" name="ip" class="equipment_sz" value=789>
</form>
a32.js:7:8
success