【发布时间】:2015-10-16 15:01:47
【问题描述】:
我正在尝试使用 ajax 发送 json
阿贾克斯:
$.ajax({
type:"POST",
url:"../create_folder/",
data: {
//csrfmiddlewaretoken: "{{ csrf_token }}",
sharedfolder // from form
},
contentType: "application/json",
dataType: "json",
success: function(data) {
debugger;
$("#folder_create").dialog('close');
$("#folder-details").pqGrid("refreshDataAndView" );
},
error: function(data){
debugger;
alert("fail");
}
});
return false;
到一个视图:
@csrf_exempt
def create_folder(request):
c = {}
c.update(csrf(request))
data = request.POST["sharedfolder"]
print type(data)
return HttpResponse(sf,content_type="application/type")
我收到此错误:
MultiValueDictKeyError at /create_folder/ "'sharedfolder'" 请求 方法:GET 请求地址:http://localhost:8000/create_folder/Django 版本:1.6.1 异常类型:MultiValueDictKeyError 异常 值:“'sharedfolder'”异常 位置:/usr/local/lib/python2.7/dist-packages/django/utils/datastructures.py 在 getitem 中,第 301 行 Python 可执行文件:/usr/bin/python Python 版本:2.7.6 Python 路径:
['/home/celestial/Documents/celestial_NAS', '/usr/lib/python2.7', '/usr/lib/python2.7/plat-x86_64-linux-gnu', '/usr/lib/python2.7/lib-tk', '/usr/lib/python2.7/lib-old', '/usr/lib/python2.7/lib-dynload', '/usr/local/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages', '/usr/lib/python2.7/dist-packages/PILcompat', '/usr/lib/python2.7/dist-packages/gtk-2.0', '/usr/lib/python2.7/dist-packages/ubuntu-sso-client'] 服务器 时间:2015 年 7 月 26 日星期日 10:30:24 +0000
可能是什么错误?
【问题讨论】:
-
您似乎收到了
GET对服务器的请求? -
您能提供表格吗?