Tuesday, December 31, 2013

Re: Displaying HTML forms through AJAX

Well Thank you very much Aaron for your suggestions, I am working on them. I am stuck in another problem here, please suggest your opinion

I am using jquery to load specific HTML Form on page (in a div).
I am using django Template generation technique to render them.

Here is the problem: I want to send a parameter in my ajax call, as form-fields need to be auto-populated with some values from DB specific to that parameter. My intention is to use .load function of jquery which passes parameters through POST (am i right?). But it is not working at all. without passing any parameter it works fine.

What I am doing:

Jquery function:
<script>
$(document).ready(function(){
  $("button").click(function(event){
  alert("ok1");
  event.preventDefault();
  var target = "{% url 'polls:demo_test'%}";
  $("#rightpan").load(target, {
  username : "arun_kaushik"
  }); 
  });
});
</script>

views.py:
def demo_test(request):
member = get_object_or_404(Userobject, username=request.POST['username'])
return render(request, 'polls/form_personal.html',{'member': member})

If I do not pass any variable in .load function it works fine and load the form (not populated ofcourse).


--
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+unsubscribe@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/fca5b57e-d110-40e3-bc95-e7f27fb61d03%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment