首页 > Web开发 > 详细

限制访问次数例子和Ajax的some

时间:2019-02-15 18:47:18      阅读:199      评论:0      收藏:0      [点我收藏+]
技术分享图片
-- html --  ajax参数的问题
 $.ajax({
            url: /ajax_test/,     提交地址
            type: get,             类型
            data: {                  数据
                name: alex,      键值对
                age: 73,
                hobby: JSON.stringify([大保健, cnb, 画大饼])
            },
            success: function (res) {  回调函数
                console.log(res)
            },
            error: function (res) {     错误
                console.log(res)
            }
        })

-- views.py --

from django.conf import global_settings
import json  
from django.http import JsonResponse

def ajax_test(request):
    
    print(request.POST)
  
    hobby = request.POST.get(hobby)  # 拿到字符串的东西
    hobby = json.loads(hobby)      # 反序列化
    print(hobby, type(hobby))     # 列表  list
    
    # return HttpResponse(json.dumps({‘xxx‘:‘xxxx‘}))  # text/html; charset=utf-8
    return JsonResponse({xxx: xxxx})  # content_type: application/json‘
    # return JsonResponse([],safe=False)   # content_type: application/json‘
View Code

 

限制访问次数例子和Ajax的some

原文:https://www.cnblogs.com/zhangchen-sx/p/10385086.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!