-- 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‘
原文:https://www.cnblogs.com/zhangchen-sx/p/10385086.html