jquery - Not seeing submitted data in Django when I do an Ajax post -
this html page:
<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"> {% 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>
this django view:
def submit_assignments(request): print request.post return httpresponse("success!")
after click assign
button, @ screen output, see printed:
<querydict: {u'csrfmiddlewaretoken': [u'lqswcqdmt8ygobqpbmw8b8mfebc9zyeo']}>
how access submitted data?
thanks!
your select
s must have name
attribute:
<select id="user_list" name="user_list" multiple='multiple' size="10"> {% u in users %} <option value="{{ u.iduser }}" >{{ u.get_long_name }}</option> {% endfor %} </select> <select id="assigned_list" name="assigned_list" multiple='multiple' size="10" style="width: 200px"> </select>
a successful control must defined within form element , must have control name.
w3schools <input>
name attribute:
note: form elements name attribute have values passed when submitting form.
Comments
Post a Comment