路飞学城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 ...
随机推荐
- 3.SpringBoot整合Thymeleaf模板
一.前言 SrpingBoot支持如JSP.Thymeleaf.FreeMarker.Mustache.Velocity等各种模板引擎,同时还为开发者提供了自定义模板扩展的支持. 使用嵌入式Servl ...
- svn_精简版【极速安装】
1.进入官网下载:http://tortoisesvn.net/ 2.进行安装. 3.官方下载汉化包 [32 位,64位] 4.安装完汉化包后,右键->Settings 5.选择语言包,确定就o ...
- Java Web学习总结(22)——使用kaptcha生成验证码
kaptcha是一个简单好用的验证码生成工具,通过配置,可以自己定义验证码大小.颜色.显示的字符等等.下面就来讲一下如何使用kaptcha生成验证码以及在服务器端取出验证码进行校验. 一.搭建测试环境 ...
- (11)Spring Boot配置ContextPath【从零开始学Spring Boot】
Spring boot默认是/ ,这样直接通过http://ip:port/就可以访问到index页面,如果要修改为http://ip:port/path/ 访问的话,那么需要在Application ...
- windows 2003一个网卡绑定多个IP地址
1.打开“网络连接”,选中需要添加多个IP的“本地连接”-->右键-->“属性”: 2.从“常规”中找到“Internet 协议(TCP/IP)属性”: 3.选择手动设置IP地址.网关.掩 ...
- RMAN主要命令 show,list,crosscheck,delete详解
Oracle RMAN 的 show,list,crosscheck,delete命令整理 Oracle RMAN 的 show,list,crosscheck,delete命令整理 1.SHOW命 ...
- 【转】Unix下C程序内存泄漏检测工具Valgrind安装与使用
Valgrind是一款用于内存调试.内存泄漏检测以及性能分析的软件开发工具. Valgrind的最初作者是Julian Seward,他于2006年由于在开发Valgrind上的工作获得了第二届Goo ...
- android 细节之An internal error occurred during: "Launching New_configuration".
今天在导入公司的一个小demo时候发现了一个非常有意思的错误. An internal error occurred during: "Launching New_configuration ...
- tiny4412开机动画、开机界面的定制 【原创】
关键词:Android linux 开机logo 开机动画 平台信息:内核:linux3.0.68 系统:android/android5.1平台:tiny4412 作者:庄泽彬(欢迎转载,请注明 ...
- [POJ 1639] Picnic Planning
[题目链接] http://poj.org/problem?id=1639 [算法] 首先,我们可以用深度优先遍历求出1号节点去除后有几个联通块 设共有T个联通块,若T > K则无解,否则 : ...