简单的html

<div>
<input type="submit" id="tes" value="tes">
<div id="test"></div>
</div>

简单的后台函数

def tes(request):
url = request.POST['url'] if 'url' in request.POST else 't'
word = request.POST['word'] if 'word' in request.POST else 't'
return HttpResponse(url+word)

直接贴javascript

$(document).ready(function() {
  //获取cookie函数
function getCookie(name) {
var cookieValue = null;
if (document.cookie && document.cookie != '') {
var cookies = document.cookie.split(';');
for (var i = 0; i < cookies.length; i++) {
var cookie = jQuery.trim(cookies[i]);
// Does this cookie string begin with the name we want?
if (cookie.substring(0, name.length + 1) == (name + '=')) {
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
break;
}
}
}
return cookieValue;
}
  //获取csrftoken对应的cookie
var csrftoken = getCookie('csrftoken');
function csrfSafeMethod(method) {
// these HTTP methods do not require CSRF protection
return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method));
}
  #cookie写入头部
$.ajaxSetup({
beforeSend: function(xhr, settings) {
if (!csrfSafeMethod(settings.type) && !this.crossDomain) {
xhr.setRequestHeader("X-CSRFToken", csrftoken);
}
}
});
$("#tes").click(function() {
// alert("t");
// $.get('http://127.0.0.1:8000/search', function(data) {
// optional stuff to do after success
// $("#test").append(data);
// });
var csrftoken =
$.post('tes/',
{
url:'url',
word:'word',
},
function(data, textStatus, xhr) {
/*optional stuff to do after success */
$("#test").append(data);
});
});
});

结果:

最新文章

  1. 使用UG UISTYLER 窗体编辑器,创建对话框 part 2
  2. stl 初步的使用
  3. c++ DISALLOW_COPY_AND_ASSIGN
  4. Ant build ${renderscript.opt.level}问题解决方案
  5. 02-自定义CALayer
  6. MySQL数据库双机热备份
  7. MySQL的alter的使用
  8. Hrbust1328 相等的最小公倍数 (筛素数,素因子分解)
  9. VS2010旗舰版安装图解
  10. NFS(网络文件系统)
  11. PHP PSR-3 日志接口规范 (中文版)
  12. Oracle EBS-SQL (SYS-24):职责列表
  13. MyBatis 笔记总结
  14. MySQL服务相关
  15. Python 黑客相关电子资源和书籍推荐
  16. Spring Security 入门(3-10)Spring Security 的四种使用方式
  17. 学JAVA第六天,运算符、表达式、if语句以及for、while、都循环
  18. js 校验 btc eth 地址
  19. 作业七:Linux内核如何装载和启动一个可执行程序
  20. Java学习笔记之Linux下的Java安装和配置

热门文章

  1. 关于百度Editor富文本编辑器 自定义上传位置
  2. python中字典的循环遍历的两种方式
  3. 【iOS开发】iOS CGRectGetMaxX/Y 使用
  4. Android问题:could not install *smartsocket* listener;Address already in use
  5. PHP变量的实现原理【转】
  6. 【题解】NOI2009管道取珠
  7. [洛谷P2147][SDOI2008]洞穴勘测
  8. NOIP2016愤怒的小鸟 [状压dp]
  9. HDU 4417 划分树写法
  10. centos关闭ipv6