2018-10-04-Python全栈开发-day62.Iframe,Formdata,Ajax
多种方式实现ajax效果
1.不依赖jquery,使用XMLHttprequest
def index(request): return render(request,'index.html') def xml(request): return HttpResponse('hello')
使用post方式上传数据
因为xml上传只有请求体,没有请求头,所以需要自己加上一个请求头,django才能识别所提交的数据
xml1.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset-UTF-8'); 在xml1.send之前加上求情头设置
2.使用iframe伪造ajax请求
使用iframe和form标签进行结合,可以伪造ajax请求,并且这种方式的兼容性最高
from django.shortcuts import render,HttpResponse # Create your views here. def index(request): if request.method=='POST': ret = {'status': True, 'message': '....'} import json return HttpResponse('hello') return render(request,'index.html')views
"en"> "UTF-8">htmlTitle 基于Iframe+Form表单