概述

  对于WEB应用程序:用户浏览器发送请求,服务器接收并处理请求,然后返回结果,往往返回就是字符串(HTML),浏览器将字符串(HTML)渲染并显示浏览器上。

1、传统的Web应用

一个简单操作需要重新加载全局数据

2、AJAX

AJAX,Asynchronous JavaScript and XML (异步的JavaScript和XML),一种创建交互式网页应用的网页开发技术方案。

异步的JavaScript:
使用 【JavaScript语言】 以及 相关【浏览器提供类库】 的功能向服务端发送请求,当服务端处理完请求之后,【自动执行某个JavaScript的回调函数】。
PS:以上请求和响应的整个过程是【偷偷】进行的,页面上无任何感知。
XML
XML是一种标记语言,是Ajax在和后台交互时传输数据的格式之一
利用AJAX可以做:
1、注册时,输入用户名自动检测用户是否已经存在。
2、登陆时,提示用户名密码错误
3、删除数据行时,将行ID发送到后台,后台在数据库中删除,数据库删除成功后,在页面DOM中将数据行也删除。

示例:通过ajax发送数据

urls.py

from django.conf.urls import url
from django.contrib import admin
from app01 import views urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^index.html$', views.index),
url(r'^ajax1.html$', views.ajax1), ]

settings.py

#注掉csrf

STATIC_URL = '/static/'
STATICFILES_DIRS = (
os.path.join(BASE_DIR,'static'),
)

views.py

from django.shortcuts import render
from django.shortcuts import HttpResponse
from app01 import models
# Create your views here. def index(request):
return render(request,'index.html') def ajax1(request):
print(request.GET)
print(request.POST)
return HttpResponse('ok')

index.html

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title> <style>
.bin{
display: inline-block;
padding:5px 10px;
background-color:coral;
color: white;
}
</style> </head>
<body>
<h1>Ajax全套</h1>
<h3>jQery Ajax</h3>
<div>
<a class="bin onclick=AjaxSubmitl();">点我</a>
</div> <script src="/static/js/jquery-3.1.1.js"></script>
<script>
function AjaxSubmitl() {
$.ajax({
url:'/ajax1.html',
type:'GET',
data:{'p':123},
success:function(arg){ }
})
} </script>
</body>
</html>

原生AJAX

Ajax主要就是使用 【XmlHttpRequest】对象来完成请求的操作,该对象在主流浏览器中均存在(除早起的IE),Ajax首次出现IE5.5中存在(ActiveX控件)。

1、XmlHttpRequest对象介绍

XmlHttpRequest对象的主要方法:

a. void open(String method,String url,Boolen async)
用于创建请求 参数:
method: 请求方式(字符串类型),如:POST、GET、DELETE...
url: 要请求的地址(字符串类型)
async: 是否异步(布尔类型) b. void send(String body)
用于发送请求 参数:
body: 要发送的数据(字符串类型) c. void setRequestHeader(String header,String value)
用于设置请求头 参数:
header: 请求头的key(字符串类型)
vlaue: 请求头的value(字符串类型) d. String getAllResponseHeaders()
获取所有响应头 返回值:
响应头数据(字符串类型) e. String getResponseHeader(String header)
获取响应头中指定header的值 参数:
header: 响应头的key(字符串类型) 返回值:
响应头中指定的header对应的值 f. void abort() 终止请求

XmlHttpRequest对象的主要属性:

a. Number readyState
状态值(整数) 详细:
0-未初始化,尚未调用open()方法;
1-启动,调用了open()方法,未调用send()方法;
2-发送,已经调用了send()方法,未接收到响应;
3-接收,已经接收到部分响应数据;
4-完成,已经接收到全部响应数据; b. Function onreadystatechange
当readyState的值改变时自动触发执行其对应的函数(回调函数) c. String responseText
服务器返回的数据(字符串类型) d. XmlDocument responseXML
服务器返回的数据(Xml对象) e. Number states
状态码(整数),如:200、404... f. String statesText
状态文本(字符串),如:OK、NotFound...

示例:通过原生XmlHttpRequest对象发送

urls.py

from django.conf.urls import url
from django.contrib import admin
from app01 import views urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^ajax1.html$', views.ajax1), ]

views.py

from django.shortcuts import render
from django.shortcuts import HttpResponse
from app01 import models
# Create your views here. def ajax1(request):
print(request.GET)
print(request.POST)
return HttpResponse('ok')

index.html

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title> <style>
.bin{
display: inline-block;
padding:5px 10px;
background-color:coral;
color: white;
}
</style> </head>
<body>
<h1>Ajax全套</h1>
<h3>jQery Ajax</h3>
<div>
<a class="bin onclick=AjaxSubmit2();">点我</a>
</div> <script src="/static/js/jquery-3.1.1.js"></script>
<script> function AjaxSubmit2() {
$.ajax({
url:'/ajax1.html',
type:'GET',
data:{'p':123},
success:function(arg){
}
})
} function AjaxSubmit2() {
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function () {
if(xhr.readyState ==4 ){
//接收完毕服务器返回的数据
console.log(xhr.responseText); }
};
xhr.open('GET','/ajax1.html?p=123');
xhr.send(null);
} </script>
</body>
</html>

示例2:

urls.py

from django.conf.urls import url
from django.contrib import admin
from app01 import views urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^index.html$', views.index),
url(r'^ajax1.html$', views.ajax1),
]

views.py

from django.shortcuts import render
from django.shortcuts import HttpResponse
from app01 import models
# Create your views here. def index(request): return render(request,'index.html') def ajax1(request):
print(request.GET)
print(request.POST)
print(request.body)
return HttpResponse('ok')

index.html

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title> <style>
.bin {
display: inline-block;
padding: 5px 10px;
background-color: coral;
color: white;
}
</style> </head>
<body>
<h1>Ajax全套</h1>
<h3>1、Ajax发送GET请求</h3>
<div>
<a class="bin onclick=AjaxSubmit1();">点我</a>
<a class="bin onclick=AjaxSubmit2();">点我</a>
</div> <h3>2、Ajax发送POST请求</h3>
<div>
<a class="bin onclick=AjaxSubmit3();">点我</a>
<a class="bin onclick=AjaxSubmit4();">点我</a>
</div> {#<h3>3、莆田</h3>#}
{#<div>#}
{# <h6>学习iframe</h6>#}
{# <div>#}
{# <input id="url" placeholder="请输入url" /><a onclick="Test1();">查看</a>#}
{# </div>#}
{# <iframe id="iframe" style="height: 800px; width: 600px;" src="http://www.autohome.com.cn"></iframe>#}
{#</div>#} <script src="/static/js/jquery-3.1.1.js"></script>
<script> function AjaxSubmit1() {
$.ajax({
url: '/index.html',
type: 'GET',
data: {'p': 123},
success: function (arg) {
}
})
} function AjaxSubmit2() {
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function () {
if (xhr.readyState == 4) {
//接收完毕服务器返回的数据
console.log(xhr.responseText); }
};
xhr.open('GET', '/ajax1.html?p=123');
xhr.send(null);
} function AjaxSubmit3() {
$.ajax({
url: '/ajax1.html',
type: 'POST',
data: {'p': 123},
success: function (arg) {
}
})
} function AjaxSubmit4() {
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function () {
if (xhr.readyState == 4) {
//接收完毕服务器返回的数据
console.log(xhr.responseText); }
};
xhr.open('POST', '/ajax1.html');
{# 设置请求头,发送post请求的时候,记得带请求头vlaue=form #}
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded;charset-urlencoded; charset-UTF-8 ');
xhr.send("p=456");
} </script>
</body>
</html>

总结:

Ajax,偷偷向后台发请求

  -XMLHttpRequest

  -手动使用

  -jQuery

“伪”AJAX

  -iframe标签

  -form表单

由于HTML标签的iframe标签具有局部加载内容的特性,所以可以使用其来伪造Ajax请求。

urls.py

from django.conf.urls import url
from django.contrib import admin
from app01 import views urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^index.html$', views.index),
url(r'^ajax1.html$', views.ajax1), ]

views.py

from django.shortcuts import render
from django.shortcuts import HttpResponse
from app01 import models def index(request):
return render(request, 'index.html') def ajax1(request):
print(request.GET)
print(request.POST)
print(request.body)
ret = {'status': True, 'message': '...'}
import json
return HttpResponse(json.dumps(ret))

index.html

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title> <style>
.bin {
display: inline-block;
padding: 5px 10px;
background-color: coral;
color: white;
}
</style> </head>
<body> <h3>3、莆田</h3>
<div>
<h6>基于Iframe+Form表单</h6>
<iframe id="iframe" name="ifra"></iframe>
<from id="fm" action="/ajax1.html" method="POST" target="ifra">
<input name="root" value="111111" />
<input type=submit" value="提交" />
</from> </div> <script src="/static/js/jquery-3.1.1.js"></script>
<script> function Test1() {
var url = $('#url').val();
$('#iframe').attr('src',url);
} function AjaxSubmit5() {
document.getElementById('fm').submit();
} function reloadframe() {
var content = this.contentWindow.document.body.innerHTML;
var obj = JSON.parse(content);
if(obj.status){
alert(obj.message);
}
} </script>
</body>
</html>

jQuery Ajax

jQuery其实就是一个JavaScript的类库,其将复杂的功能做了上层封装,使得开发者可以在其基础上写更少的代码实现更多的功能。

  • jQuery 不是生产者,而是大自然搬运工。
  • jQuery Ajax本质 XMLHttpRequest 或 ActiveXObject

注:2.+版本不再支持IE9以下的浏览器

jQuery Ajax 方法列表

jQuery.get(...)
所有参数:
url: 待载入页面的URL地址
data: 待发送 Key/value 参数。
success: 载入成功时回调函数。
dataType: 返回内容格式,xml, json, script, text, html jQuery.post(...)
所有参数:
url: 待载入页面的URL地址
data: 待发送 Key/value 参数
success: 载入成功时回调函数
dataType: 返回内容格式,xml, json, script, text, html jQuery.getJSON(...)
所有参数:
url: 待载入页面的URL地址
data: 待发送 Key/value 参数。
success: 载入成功时回调函数。 jQuery.getScript(...)
所有参数:
url: 待载入页面的URL地址
data: 待发送 Key/value 参数。
success: 载入成功时回调函数。 jQuery.ajax(...) 部分参数: url:请求地址
type:请求方式,GET、POST(1.9.0之后用method)
headers:请求头
data:要发送的数据
contentType:即将发送信息至服务器的内容编码类型(默认: "application/x-www-form-urlencoded; charset=UTF-8")
async:是否异步
timeout:设置请求超时时间(毫秒) beforeSend:发送请求前执行的函数(全局)
complete:完成之后执行的回调函数(全局)
success:成功之后执行的回调函数(全局)
error:失败之后执行的回调函数(全局) accepts:通过请求头发送给服务器,告诉服务器当前客户端课接受的数据类型
dataType:将服务器端返回的数据转换成指定类型
"xml": 将服务器端返回的内容转换成xml格式
"text": 将服务器端返回的内容转换成普通文本格式
"html": 将服务器端返回的内容转换成普通文本格式,在插入DOM中时,如果包含JavaScript标签,则会尝试去执行。
"script": 尝试将返回值当作JavaScript去执行,然后再将服务器端返回的内容转换成普通文本格式
"json": 将服务器端返回的内容转换成相应的JavaScript对象
"jsonp": JSONP 格式
使用 JSONP 形式调用函数时,如 "myurl?callback=?" jQuery 将自动替换 ? 为正确的函数名,以执行回调函数 如果不指定,jQuery 将自动根据HTTP包MIME信息返回相应类型(an XML MIME type will yield XML, in 1.4 JSON will yield a JavaScript object, in 1.4 script will execute the script, and anything else will be returned as a string converters: 转换器,将服务器端的内容根据指定的dataType转换类型,并传值给success回调函数
$.ajax({
accepts: {
mycustomtype: 'application/x-some-custom-type'
}, // Expect a `mycustomtype` back from server
dataType: 'mycustomtype' // Instructions for how to deserialize a `mycustomtype`
converters: {
'text mycustomtype': function(result) {
// Do Stuff
return newresult;
}
},
});

Ajax上传文件

- jQuery

-原生

以上两种方式可利用fromData对象,来封装用户提交的数据

- Iframe+Form

示例: 文件上传

urls.py

from django.conf.urls import url
from django.contrib import admin
from app01 import views urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^index.html$', views.index),
url(r'^ajax1.html$', views.ajax1),
]

views.py

from django.shortcuts import render
from django.shortcuts import HttpResponse
from app01 import models def index(request):
return render(request, 'index.html') def ajax1(request):
print(request.GET)
print(request.POST)
print(request.FILES) #image/1.jpg
ret = {'status': True, 'message': '...'}
import json
return HttpResponse(json.dumps(ret))

index.html

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title> <style>
.bin {
display: inline-block;
padding: 5px 10px;
background-color: coral;
color: white;
}
</style> </head>
<body> <h6>基于Iframe+Form表单</h6>
<div>
<iframe id="iframe" name="ifra"></iframe>
<from id="fm" action="/ajax1.html" method="POST" target="ifra">
<input name="root" value="111111"/>
<a onclick="AjaxSubmit5()">提交</a>
</from>
</div> <h3>4.文件上传</h3>
<input type="file" id="img"/>
<a class="bin" onclick="AjaxSubmit6();">上传</a>
<a class="bin" onclick="AjaxSubmit7();">上传</a> <iframe style="display: none" id="iframe" name="ifra1"></iframe>
<from id="fm1" action="/ajax1.html" method="POST" enctype="multipart/form-data" target="ifra1">
<input type="text" id="k1" />
<input type="text" id="k2" />
<input type="file" id="k3" />
<a onclick="AjaxSubmit8()">提交</a>
</from> <script src="/static/js/jquery-3.1.1.js"></script>
<script>
function AjaxSubmit6() {
var data = new FormData();
data.append('k1', 'v1');
data.append('k2', 'v2');
{# 选择器,索引0代指上传的文件对象#}
data.append('k3',document.getElementById('img').files[0]); $.ajax({
url: '/ajax1.html',
type: 'POST',
data: data,
success: function (arg) {
console.log(arg)
},
processData: false,
contentType: false
})
} function AjaxSubmit7() {
var data = new FormData();
data.append('k1', 'v1');
data.append('k2', 'v2');
data.append('k3',document.getElementById('img').files[0]); var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function () {
if (xhr.readyState == 4) {
//接收完毕服务器返回的数据
console.log(xhr.responseText);
}
};
xhr.open('POST', '/ajax1.html');
xhr.send(data);
} function AjaxSubmit8() {
document.getElementById('iframe1').onload = reloadframe1;
document.getElementById('fm1').submit();
} function reloadframe1() {
var content = this.contentWindow.document.body.innerHTML;
var obj = JSON.parse(content);
console.log(obj);
}
</script>
</body>
</html>

示例:实现文件上传,自动提交

urls.py

from django.conf.urls import url
from django.contrib import admin
from app01 import views urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^upload.html$', views.upload),
url(r'^upload_img.html$', views.upload_img),
]

views.py

from django.shortcuts import render
from django.shortcuts import HttpResponse
from app01 import models
import json
import os
import uuid def upload(request):
return render(request,'upload.html') def upload_img(request):
nid = str(uuid.uuid4())
ret = {'status':True,'data':None,'message':None}
obj = request.FILES.get('k3') file_path = os.path.join('static', nid+obj.name)
f = open(obj.name,'wb')
for line in obj.chunks():
f.write(line)
f.close()
ret['data'] = file_path
return HttpResponse(json.dumps(ret))

upload.html

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
.btn{
display: inline-block;
padding: 5px 10px;
background-color: coral;
color: white;
}
</style>
</head>
<body> <iframe style="display: none" id="iframe1" name="ifra1"></iframe>
<form id="fm1" action="/upload_img.html" method="POST" enctype="multipart/form-data" target="ifra1">
<input type="file" name="k3" onchange="uploadFile();" />
</form>
<h3>预览</h3>
<div id="preview">
</div>
<script src="/static/js/jquery-3.1.1.js"></script>
<script> function uploadFile() {
document.getElementById('iframe1').onload = reloadIframe1;
document.getElementById('fm1').submit();
}
function reloadIframe1() {
var content = this.contentWindow.document.body.innerHTML;
var obj = JSON.parse(content); var tag = document.createElement('img');
tag.src = obj.data;
$('#preview').empty().append(tag);
}
</script>
</body>
</html>

跨域AJAX,JSONP

由于浏览器存在同源策略机制,同源策略阻止从一个源加载的文档或脚本获取或设置另一个源加载的文档的属性。

特别的:由于同源策略是浏览器的限制,所以请求的发送和响应是可以进行,只不过浏览器不接受罢了。

浏览器同源策略并不是对所有的请求均制约:

  • 制约: XmlHttpRequest
  • 不叼: img、iframe、script等具有src属性的标签

跨域,跨域名访问,如:http://www.c1.com 域名向 http://www.c2.com域名发送请求。

浏览器同源策略:XMLHttpRequest
巧妙的机制JSONP JSONP:
利用创建script块,在期中执行src属性为:远程url
函数(返回值) function 函数(arg){ }

1、JSONP实现跨域请求

  JSONP(JSONP - JSON with Padding是JSON的一种“使用模式”),利用script标签的src属性(浏览器允许script标签跨域)

目录结构

示例:

urls.py

from django.conf.urls import url
from django.contrib import admin
from app01 import views urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^jsonp.html$', views.jsonp),
url(r'^ajax3.html$', views.ajax3),
]

views.py

from django.shortcuts import render
from django.shortcuts import HttpResponse
from app01 import models def jsonp(request):
return render(request, 'jsonp.html') def ajax3(request):
return HttpResponse('本服务器发送的请求')

jsonp.html

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title> </head>
<body> <div id="content"></div>
<input type="button" value="发送1" onclick="submitJsonp1();" />
<input type="button" value="发送2" onclick="submitJsonp2();" />
<input type="button" value="发送3" onclick="submitJsonp3();" />
<input type="button" value="发送4" onclick="submitJsonp4();" />
<script src="/static/js/jquery-3.1.1.js"></script>
<script>
function submitJsonp1() {
$.ajax({
url: '/ajax3.html',
type: 'GET',
data: {nid:2},
success:function (arg) {
$('#content').html(arg);
}
})
} function submitJsonp2() {
var tag = document.createElement('script');
tag.src = 'http://127.0.0.1:9000/xiaokai.html';
document.head.appendChild(tag);
document.head.removeChild(tag);
} function fuck(arg) {
$('#content').html(arg);
} function submitJsonp3() {
var tag = document.createElement('script');
tag.src = 'http://www.jxntv.cn/data/jmd-jxtv2.html?callback=list&_=1454376870403';
document.head.appendChild(tag);
document.head.removeChild(tag);
} {# function list(arg) {#}
{# console.log(arg);#}
{#}#} function submitJsonp4() {
$.ajax({
url: 'http://127.0.0.1:9000/xiaokai.html',
type: 'POST',
dataType: 'jsonp',
jsonp: 'callback',
jsonpCallback: 'func'
})
}
function func(arg) {
console.log(arg);
}
</script>
</body>
</html>

另一个返回数据页面

urls.py

from django.conf.urls import url
from django.contrib import admin
from app01 import views urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^xiaokai.html/',views.xiaokai),
]

views.py

from django.shortcuts import render
from django.shortcuts import HttpResponse # Create your views here. def xiaokai(request): return HttpResponse('fuck("我爱北京天安门");')

2、CORS

随着技术的发展,现在的浏览器可以支持主动设置从而允许跨域请求,即:跨域资源共享(CORS,Cross-Origin Resource Sharing),其本质是设置响应头,使得浏览器允许跨域请求。

Python开发之AJAX全套的更多相关文章

  1. 转Python开发之AJAX全套

    转自:https://www.cnblogs.com/nulige/p/6603415.html#4206261

  2. Python开发之AJAX

    一.概述 对于WEB应用程序:用户浏览器发送请求,服务器接收并处理请求,然后返回结果,往往返回就是字符串(HTML),浏览器将字符串(HTML)渲染并显示浏览器上. 1.传统的Web应用:一个简单操作 ...

  3. python开发之路:python数据类型(老王版)

    python开发之路:python数据类型 你辞职当了某类似微博的社交网站的底层python开发主管,官还算高. 一次老板让你编写一个登陆的程序.咔嚓,编出来了.执行一看,我的妈,报错? 这次你又让媳 ...

  4. Python3.6编译安装以及python开发之virtualenv与virtualenvwrapper

    Python3.6编译安装 下载python源码包 先到安装目录 cd /opt 下载源码包 wget https://www.python.org/ftp/python/3.6.2/Python-3 ...

  5. Python开发之IDE选择

    Python开发之IDE 一.为什么用IDE 到现在为止,谁还不是个写过代码的人啦,但你有没有发现,每次写代码要新建文件.写完保存时还要选择存放地点,执行时还要切换到命令行调用python解释器,好麻 ...

  6. Python 开发之路

    强烈推荐地表最强博客:http://www.cnblogs.com/wupeiqi Python开发[第一篇]:目录 Python开发[第二篇]:初识Python Python开发[第三篇]:Pyth ...

  7. python自动开发之(ajax)第二十天

    1.Django请求的生命周期 路由系统 -> 试图函数(获取模板+数据=>渲染) -> 字符串返回给用户 2.路由系统 /index/ -> 函数或类.as_view() / ...

  8. Python开发之路

    详细内容见老男孩<<python入门与提高实践>> 第一篇:python入门 第二篇:数据类型.字符编码.文件处理 第三篇:函数 第四篇:模块与包 第五篇:常用模块 第六篇:面 ...

  9. [置顶]Python开发之路

    阅读目录   第一篇:python入门 第二篇:数据类型.字符编码.文件处理 第三篇:函数 第四篇:模块与包 第五篇:常用模块 第六篇:面向对象 第七篇:面向对象高级 第八篇:异常处理 第九篇:网络编 ...

随机推荐

  1. YAHOO 35条前端优化建议(转)

    Yahoo!的 Exceptional Performance团队为改善 Web性能带来最佳实践.他们为此进行了一系列的实验.开发了各种工具.写了大量的文章和博客并在各种会议上参与探讨.总结出了一系列 ...

  2. 爱奇艺全国高校算法大赛初赛B

    二分,验证. 二分一下答案,然后验证一下统计个数能否满足即可. #include <cstdio> #include <cmath> #include <cstring& ...

  3. UWP数据分享

    前言 本文介绍如何在通用Windows平台(UWP)应用程序中支持共享合同.共享合同是一种在应用程序之间快速共享数据(如文本,链接,照片和视频)的简便方法.例如,用户可能想要使用社交网络应用与他们的朋 ...

  4. 推荐2本学习java书和PDF

    推荐2本学习java书和PDF下载地址 <深入理解Java虚拟机:JVM高级特性与最佳实践>共分为五大部分,围绕内存管理.执行子系统.程序编译与优化.高效并发等核心主题对JVM进行了全面而 ...

  5. Node.js下的Hello World

    Node.js技术现在可谓是如火如荼,前后端都统一为Javascript的体验绝对是受到了很多人的青睐,我都后悔以前没抽时间好好学一学Javascript了. 首先,我来介绍一下Node.js.本人实 ...

  6. android 启动流程

    韩梦飞沙  韩亚飞  313134555@qq.com  yue31313  han_meng_fei_sha adb shell 后  用 ps 命令 回车 可以看到 运行的进程. 如下结果: ct ...

  7. 51nod1203 JZPLCM 线段树 + 扫描线

    不算很难的一道题 原题的数据虽然很小,但是我们不能欺负它,我们就要当$S[i] \leqslant 10^9$来做这题 最小公倍数 = 所有的质因数取可能的最大幂相乘 对于$> \sqrt S$ ...

  8. [CodeForces-375E]Red and Black Tree

    题目大意: 给你一棵带边权的树,每个结点可能是红色或者黑色,你可以交换若干个点对使得任意一个红点到达与其最近的黑点的距离小于等于m. 思路: 动态规划. f[i][j][k]表示以i为根的子树中,连向 ...

  9. python一行代码开启http

    python -m SimpleHTTPServer 8000 & 监听8000端口 浏览器用127.0.0.1:8000访问 如果出现no module named SimpleHTTPSe ...

  10. Makefile-函数patsubst

    比方说你在makefile里定义了一个变量,内容是一堆 .c 文件的的名字,如 SRC = aaa.c bbb.c my.c his.c你可以用 patsubst 根据某种模式,将这些名字改成另外的, ...