路飞学城Python-Day107
- 同步交互:客户端发出一个请求后,需要等待服务器响应结束后,才能发出第二个请求;
- 异步交互:客户端发出一个请求后,无需等待服务器响应结束,就可以发出第二个请求。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Index</title>
<script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/1.6.4/jquery.min.js"></script>
</head>
<body>
<h2>this is index</h2>
<button id="btn">ajax</button>
<hr>
<input type="text" id="num1">+<input type="text" id="num2"> = <input type="text" id="res">
<button class="cal">计算</button>
<script>
$('#btn').click(function () {
{#alert('123');#}
{# 发送ajax请求#}
$.ajax({
{#请求的方式参数是不能变更的#}
url: "/test/",
type: 'get',
data: {a: 1, b: 2},
success: function (data) { //回调函数
console.log(data)
}
})
});
$('.cal').click(function () {
$.ajax({
url: '/cal/',
type: 'post',
data: {
num1: $('#num1').val(),
num2: $('#num2').val(),
},
success: function (data) {
console.log(data);
$('#res').val(data);
}
});
});
</script>
</body> </html>
from django.shortcuts import render, HttpResponse # Create your views here.
from app01.models import User def index(request):
# obj = User.objects.create(name='pandaboy', pwd= '123')
# obj.save()
return render(request, 'index.html') def test(request):
print(request.GET)
return HttpResponse('OK')
# return render(request, 'test.html') def cal(request):
print(request.POST)
n1 = request.POST.get('num1')
n2 = request.POST.get('num2')
res = int(n1)+int(n2)
return HttpResponse(res) def login(request):
print(request.POST)
user1 = request.POST.get('user')
pwd = request.POST.get('pwd')
user = User.objects.filter(name=user1, pwd=pwd).first()
res = {'user': None, 'msg':None}
if user:
res['user'] = user.name
print('验证成功')
else:
res['msg'] = 'username or pwd wrong'
import json
return HttpResponse(json.dumps(res)) def fileput(request):
if request.method == 'POST':
print(request.POST)
print(request.body) #请求头过来的请求体
# print(request.FILES)
# file_obj = request.FILES.get('avtar')
# with open(file_obj.name, 'wb') as f:
# for line in file_obj:
# f.write(line)
return HttpResponse('OK')
return render(request, 'fileput.html')
92-基于Form表单的文件上传
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Index</title>
<script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/1.6.4/jquery.min.js"></script>
</head>
<body>
<h2>this is index</h2>
<button id="btn">ajax</button>
<hr>
<input type="text" id="num1">+<input type="text" id="num2"> = <input type="text" id="res"><button class="cal">计算</button>
<hr>
<form action="">
用户名<input type="text" id="user"/>
密码<input type="password" id="pwd"/>
<input type="button" value="submit" class="loginbtn"/>
</form>
<script>
$('#btn').click(function () {
{#alert('123');#}
{# 发送ajax请求#}
$.ajax({
{#请求的方式参数是不能变更的#}
url:"/test/",
type:'get',
data:{a:1, b:2},
success:function (data) { //回调函数
console.log(data)
}
})
});
$('.cal').click(function () {
$.ajax({
url: '/cal/',
type:'post',
data:{
num1:$('#num1').val(),
num2 :$('#num2').val(),
},
success:function (data) {
console.log(data);
$('#res').val(data);
}
});
});
$('.loginbtn').click(function () {
$.ajax({
url:'/login/',
type:'post',
data:{
"user": $('#user').val(),
"pwd":$('#pwd').val(),
},
success:function (data) {
{#console.log(data);#}
var data_1 = JSON.parse(data);
console.log(data_1);
if (data_1.user){
location.href = 'http://www.baidu.com'
}else {
alert(data_1.msg);
} }, });
});
</script>
</body> </html>
1 application/x-www-form-urlencoded
2 multipart/form-data
3 application/json
路飞学城Python-Day107的更多相关文章
- 路飞学城—Python爬虫实战密训班 第三章
路飞学城—Python爬虫实战密训班 第三章 一.scrapy-redis插件实现简单分布式爬虫 scrapy-redis插件用于将scrapy和redis结合实现简单分布式爬虫: - 定义调度器 - ...
- 路飞学城—Python爬虫实战密训班 第二章
路飞学城—Python爬虫实战密训班 第二章 一.Selenium基础 Selenium是一个第三方模块,可以完全模拟用户在浏览器上操作(相当于在浏览器上点点点). 1.安装 - pip instal ...
- 路飞学城Python爬虫课第一章笔记
前言 原创文章,转载引用务必注明链接.水平有限,如有疏漏,欢迎指正. 之前看阮一峰的博客文章,介绍到路飞学城爬虫课程限免,看了眼内容还不错,就兴冲冲报了名,99块钱满足以下条件会返还并送书送视频. 缴 ...
- 路飞学城-Python开发集训-第3章
学习心得: 通过这一章的作业,使我对正则表达式的使用直接提升了一个level,虽然作业完成的不怎么样,重复代码有点多,但是收获还是非常大的,有点找到写代码的感觉了,遗憾的是,这次作业交过,这次集训就结 ...
- 路飞学城-Python开发集训-第1章
学习体会: 在参加这次集训之前我自己学过一段时间的Python,看过老男孩的免费视频,自我感觉还行,老师写的代码基本上都能看懂,但是实际呢?....今天是集训第一次交作业的时间,突然发现看似简单升级需 ...
- 路飞学城-Python开发集训-第4章
学习心得: 学习笔记: 在python中一个py文件就是一个模块 模块好处: 1.提高可维护性 2.可重用 3.避免函数名和变量名冲突 模块分为三种: 1.内置标准模块(标准库),查看所有自带和第三方 ...
- 路飞学城-Python开发集训-第2章
学习心得: 这章对编码的讲解超级赞,现在对于编码终于有一点认知了,但还没有大彻大悟,还需要更加细心的琢磨一下Alex博客和视频,以前真的是被编码折磨死了,因为编码的问题而浪费的时间很多很多,现在终于感 ...
- 路飞学城-Python开发-第二章
''' 数据结构: menu = { '北京':{ '海淀':{ '五道口':{ 'soho':{}, '网易':{}, 'google':{} }, '中关村':{ '爱奇艺':{}, '汽车之家' ...
- 路飞学城-Python开发-第三章
# 数据结构: # goods = [ # {"name": "电脑", "price": 1999}, # {"name&quo ...
- 路飞学城-Python开发-第一章
# 基础需求: # 让用户输入用户名密码 # 认证成功后显示欢迎信息 # 输错三次后退出程序 username = 'pandaboy' password = ' def Login(username ...
随机推荐
- Solr与Elasticsearch比较
Solr优点1.Solr有一个更大.更成熟的用户.开发和贡献者社区.2.支持添加多种格式的索引,如:HTML.PDF.微软 Office 系列软件格式以及 JSON.XML.CSV 等纯文本格式.3. ...
- XHXJ's LIS
XHXJ's LIS Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Probl ...
- windows 2003一个网卡绑定多个IP地址
1.打开“网络连接”,选中需要添加多个IP的“本地连接”-->右键-->“属性”: 2.从“常规”中找到“Internet 协议(TCP/IP)属性”: 3.选择手动设置IP地址.网关.掩 ...
- 关于使用sudo命令后找不到JAVA_HOME的问题
今天在虚拟机搭建zookeeper环境,结果死活运行不起来,唯一的信息只有out文件里“没有java命令”这一个提示,找来找去发现是找不到java运行环境.可是很奇怪,明明我已经配置了,而且在终端执行 ...
- ZOJ2724_Windows Message Queue(STL/优先队列)
解题报告 题意: 看输入输出就非常明确. 思路: 优先队列. #include <algorithm> #include <iostream> #include <cst ...
- 高效使用hive
工作中常常使用hive.熟练使用hvie的配置參数能够更加高效的使用Hive Hive option: hive -f script.hql : 从文件script.hql中的读取hql运行 hi ...
- OpenCV打开摄像头失败
<span style="font-family: Arial, Helvetica, sans-serif;">#include <stdio.h>< ...
- 问题2-:Syntax error on tokens, delete these tokens
出现原因:拷贝下来的代码缺少{左大括号 然后运行时run as 没有选到java application 是因为没有main方法 加个public static void main(String() ...
- LLVM每日谈之十九 LLVM的第一本系统的书<Getting Started with LLVM Core Libraries>
作者:史宁宁(snsn1984) LLVM最终有了一本系统的书了--<Getting Started with LLVM Core Libraries>. 这本书号称是LLVM的第一本书, ...
- [ Javascript ] 内存泄露以及循环引用解析
内存泄露 在javascript中,我们非常少去关注内存的管理. 我们创建变量,使用变量,浏览器关注这些底层的细节都显得非常正常. 可是当应用程序变得越来越复杂而且ajax化之后,或者用户在一个页面停 ...