So I'm trying to write an ajax script that post data to django without 
having to leave the page. Currently it is on submit however eventually im 
going to put it on a timer.

Right now the function outputs to the console as a success but no data is 
returned from django.


Here is my ajax

<script type="text/javascript">
$(document).ready(function() {
    $('#get_info').submit(function() { 
        $.ajax({
            type: $('#get_info').attr('POST'),
            url: $('#get_info').attr('action'),
            data: $('#get_info').serialize(),
            success: function (data) {
                console.log('done');
                console.log($('#get_info').serialize());
            },
            error: function(data) {
                console.log('something went wrong');
            }
        });
        return false;
    });
    });
</script>

Here is the serialized data it outputs to the console.

"done" vmstatus:34
"csrfmiddlewaretoken=HApMk9LWlxNUdlJaD4kj0WZkCTki4hin&selected_customer=24&user=True"

However no django data is returned after that? I know the django code works 
because I was using regular form submission to test it.

here is my views code:

   if request.method == 'POST':   
      posted_data = request.POST.copy()
      customer_id = int(posted_data['selected_customer'])
      for customer in customers:
         if customer.customer_id == customer_id:
            selected_customer = ((decrypt('secretkey', customer.
customer_name), int(customer.customer_id)))       
         customer_list.append((decrypt('secretkey', customer.customer_name), 
int(customer.customer_id))) 
         
      
      vms = PortalCommandCenter.objects.filter(customer_id = customer_id).
distinct('vm_id')
      
           
      context = {'user.is_superuser':user.is_superuser, 
                            'customer_list':customer_list,
                            'customer_id':customer_id,
                            'vms':vms,
                            'posted_data':posted_data,
                            'selected_customer':selected_customer
                             }
         
      return render(request, 'vmstatus.html', context) 

do I need to serialize the data as json so that it is still a dictionary if 
so how do I do that?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/75ce4888-933c-461a-8709-35bb7cfdd216%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to