On Jun 26, 11:36 pm, elspiko <[EMAIL PROTECTED]> wrote: > Hi all, > > I've fairly new to django but i'm loving it! > > I've got some draggable panels on a site and want to save their > positions so when a user logs back in, the panels are in the same > place when they last hit the save button. What I'm doing is (using > jQuery) retrieving the id's of the panels, putting them into an array, > and using ajax to pass the array to the server: > > var data = [] > $('#left > div').each(function() { > data.push($(this).attr('id')); > }); > var Left = 'Left<br />'; > for(x in data) > { > Left += data[x] + " in pos " + x + "<br />"; > } > Left += "<br />"; > $('#var_test').html(Left); > > $.post("/post_test/",{'data[]': data }); > > Using firebug, I can see that the data is being posted correctly. > > Below is the view (abridged): > > def post_handler(request): > post_text = request.POST.getlist('data') > user = User.objects.get(id=2) # for debugging purposes > for x in range( len(post_text)-1 ): > name = post_text[x] > panel = > user.panels_set.get(name__istartswith=name,side="left") > panel.order = x > panel.save() > > The problem is its not saving to the database, I'm assuming it to do > with the way I'm accessing the POST data, but I can't work it out. > I've tried post_text = request.POST['data'], but that didn't work > either, > > I really am at a loose end with this...please help!!
You are POSTing the data with the dictionary key 'data[]'. But your view is expecting the value 'data'. Your jQuery post line should just be : $.post("/post_test/",{'data': data }); I suspect this is a habit picked up from PHP, but you don't need it here. -- DR. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---