django 提交json以及返回json
code
html console.log("{% url 'addbook' %}"); var msg={"hotelid":"0813"} $.ajax({ type:"POST", url:"{% url 'addbook' %}", contentType:'application/json', data:JSON.stringify(msg), dataType:'JSON', error:function(data) { console.log("error"); }, success:function(data) { console.log("success"); } }); urls.py url(r'^addbook',k.addbook,name="addbook"), views.py def addbook(request): request_data=request.body request_dict=json.loads(request_data.decode('utf-8')) print(request_dict) data={"code":200,"msg":"保存成功!"} return HttpResponse(json.dumps(data,ensure_ascii=False),content_type="application/json,charset=utf-8")