ajax+jquery+django
2014-02-26 13:09
197 查看
前端的ajax+jquery+django服务端
前端代码:
第一种,直接用$.post或者$.get发送,具体参数为
$.post(url,[data],[calback],[type])
$.get(url,[data],[callback])
以post方式发送为例:
$(document).ready(function () {
$('#jqueryajax').click(function(){
$.post('/home/back/',{name:'chen', age:12},
function(data){
alert(data)
}
);
});
});
第二种:控制ajax的详情,效果和第一种方法是一样的,个人感觉这个阅读起来更清晰:
$(document).ready(function () {
$('#jqueryajax').click(function(){
$.ajax({
type:'POST',
url:'/home/back/',
data:{name:'nataila', age:35},
success:function(data){
alert(data)
}
});
});
});
后端代码是不变的:
def back(request):
>---if request.method == 'POST':
>--->---content = request.POST.get('name')
>--->---print request.POST
>--->---return HttpResponse('POST receive success, name is ' + content)
>---else:
>--->---content = request.GET.get('name')
>--->---return HttpResponse('GET receive success, name is ' + content)
此文仅供新手参考
前端代码:
第一种,直接用$.post或者$.get发送,具体参数为
$.post(url,[data],[calback],[type])
$.get(url,[data],[callback])
以post方式发送为例:
$(document).ready(function () {
$('#jqueryajax').click(function(){
$.post('/home/back/',{name:'chen', age:12},
function(data){
alert(data)
}
);
});
});
第二种:控制ajax的详情,效果和第一种方法是一样的,个人感觉这个阅读起来更清晰:
$(document).ready(function () {
$('#jqueryajax').click(function(){
$.ajax({
type:'POST',
url:'/home/back/',
data:{name:'nataila', age:35},
success:function(data){
alert(data)
}
});
});
});
后端代码是不变的:
def back(request):
>---if request.method == 'POST':
>--->---content = request.POST.get('name')
>--->---print request.POST
>--->---return HttpResponse('POST receive success, name is ' + content)
>---else:
>--->---content = request.GET.get('name')
>--->---return HttpResponse('GET receive success, name is ' + content)
此文仅供新手参考
相关文章推荐
- django 1.4 利用jquery实现ajax ‘get|post’异步请求
- Django中怎么利用jquery完成ajax的验证和数据提交
- How to POST a django form with AJAX & jQuery
- Django+Ajax+jQuery实现网页动态更新的实例
- Ajax (jquery)实现智能提示搜索框(in Django)
- DJango 下 Jquery -- Ajax的使用
- [Django 1.5] jQuery/Ajax 在Django使用 ,如何更新模板里里变量
- Native Ajax in Django and jQuery
- Ajax 和 jQuery 实现进度条+上传文件到Django
- Django中使用jquery的ajax进行数据交互的实例代码
- Django1.7+JQuery+Ajax集成小例子
- 第五篇文章:在Django中用Jquery实现Ajax
- Django+Ajax+jQuery实现网页动态更新
- 十九 Django 1.5.4 jquery ajax bootstrap
- django用jquery的ajax提交表单,中间件的CsrfViewMiddleware问题
- Django+Jquery+Ajax+验证码登录案例系列之十二
- Django+JQuery+Ajax+Post方案中的问题及解决
- AJAX in Django with jQuery
- 使用Python的Django框架结合jQuery实现AJAX购物车页面
- 使用Python的Django框架结合jQuery实现AJAX购物车页面