Django ajax passing variable to the views -


i'm new django + ajax. problem can't value ajax post request. i'm using jquery post.

my task sort draggable list item. drag , drop not problem. getting values post request problem. returns multivaluedictkeyerror

"key 'ages' not found in <querydict: {u'action': [u'updaterecords'], u'ages[]': [u'80', u'81', u'79', u'82', u'83', u'84', u'85', u'86']}>"

here ajax:

$(function() {      var url = ""; /* won't place it*/     $("ul#ages").sortable({ opacity: 0.6, cursor: 'move', update: function() {             var order = $(this).sortable("serialize") + '&action=updaterecords';             $.post(url, order, function(theresponse){                 alert('success');             });         }     }); }); 

here views:

if request.is_ajax():         if request.post['action'] == "updaterecords":             update_record_array = request.post['ages']              order_counter = 1;              record_id in update_record_array:                 age.objects.filter(id=record_id).update(order_id=order_counter)                 order_counter += 1 

can me out?

thanks!

the error message shows wrong - you're looking key ages, you're sending called ages[] square brackets.

if you've put brackets in field name, don't need them - that's php-ism. (it might not fault: jquery has been known add them itself.) in case, you'll want use request.post.getlist(fieldname) list of multiple values associated key.


Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -