ajax 前端发含有列表的数据
发布时间:2020-12-16 02:59:47 所属栏目:百科 来源:网络整理
导读:在前端页面也可以给后端发送一个包含列表的数据 html bodyh3index页面 /h3input type= " text " name= " cal_1 " +input type= " text " name= " cal_2 " =input type= " text " name= " cal_3 " button id= " b2 " 计算/buttonbrbutton id= " b3 " 测试的数
在前端页面也可以给后端发送一个包含列表的数据 html <body> <h3>index页面 </h3> <input type="text" name="cal_1">+ <input type="text" name="cal_2">= <input type="text" name="cal_3"> <button id="b2">计算</button> <br> <button id="b3">测试的数据</button> <script src="/static/js/jquery.js"></script> <script> $("#b3").click(function () { $.ajax({ url: "/ajax_test/",//往这个地址发 type: "post",data: { name: "alex",age: "33", hobby: JSON.stringify(["抽烟","喝酒","烫头"])//传多个值的时,用json字符串 },success: function (res) { $("[name=‘cal_3‘]").val(res) },}) }) </script> 但是前端发送的数据中为什么没有csrftoken呢??? views视图部分 ? def ajax_test(request): print(request.POST) print(request.POST.get("name")) print(request.POST.get("age")) hobby=request.POST.get("hobby") print(json.loads(hobby))# 把接受的json字符串反序列化 return HttpResponse("ajax test") (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |