这是我的html页面:
<div>
<form id="assignment_form" action="/submit-assignments/" method="post" accept-charset="utf-8">
{% csrf_token %}
<!-- Fields here -->
<select id="user_list" multiple='multiple' size="10">
{% for u in users %}
<option value="{{ u.iduser }}" >{{ u.get_long_name }}</option>
{% endfor %}
</select>
<select id="assigned_list" multiple='multiple' size="10" style="width: 200px">
</select>
<input id="assign" type="submit" value="Assign"/></input>
</form>
</div>
<script type="text/JavaScript">
$(document).ajaxSend(function(event, xhr, settings) {
//cookies stuff
}
$(document).ready(function() {
$("#assignment_form").submit(function(event){
event.preventDefault();
$.ajax({
type:"POST",
url:"/brewkeep/submit-assignments/",
data: $("#assignment_form").serialize(),
success: function(data) {
alert(data);
}
});
});
});
</script>
这是我的 Django 视图:
def submit_assignments(request):
print request.POST
return HttpResponse("Success!")
单击Assign
按钮后,我查看屏幕输出,这是我看到的打印内容:
<QueryDict: {u'csrfmiddlewaretoken': [u'LqSWcQDMt8YGoBqpBMw8B8mfebC9ZyEo']}>
如何访问我提交的数据?
谢谢!