Re: Django-Ajax Issue

2013-07-15 Thread Subodh Nijsure
I am not sure what you mean by taking you to post view of the function.

That aside, you need to include  csrfmiddlewaretoken: '{{ csrf_token
}}' in your data: section.

   data: {
 'keyword': search_for,
 'filter': rval,
csrfmiddlewaretoken: '{{ csrf_token }}'
},

-Subodh

On Sun, Jul 14, 2013 at 8:19 AM, vijay shanker  wrote:
> Hey all
> I am trying to make a simple ajax call to show items retrieved from
> database.
> I am displaying bunch of fields like a text input for keyword and radio
> button for filter in a form like this:
>
> {% csrf_token %}
> 
>  Search 
> 
> 
> 
>  checked='checked'/>All
>  value="paying"/>Paying
>  value="uploaded"/>Uploaded
>  />Staff Pick
>  
> 
>
> This form is displayed by a function which inherits generic View class, from
> its get method.
>
> class Home(View):
> def get(self,request, *args, **kwargs):
> return render_to_response('items/search_page.html', context_instance
> = RequestContext(request) )
> def post(self, request, *args, **kwargs):
> print 'in home post'
>
> What puzzles me is that when i am trying to submit the form data via ajax
> call (on same page) with jquery when someone clicks on search button, it
> takes me to post view of Home and not on to other function i have defined.
> The javascript on the html page is:
> 
>function search(e) {
> e.preventDefault();
> search_for = $("#search").val()
> rval = $('input:radio[name=fancy_radio]:checked').val()
> $.ajax({
> url:"/search/",
> method : "POST",
> data : { 'keyword': search_for, 'filter': rval },
> success:function(result){
> alert(result)
> }
> });
>}
> 
>
> why is this happening ?
>
> --
> 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.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.




Django-Ajax Issue

2013-07-14 Thread vijay shanker
Hey all
I am trying to make a simple ajax call to show items retrieved from 
database.
I am displaying bunch of fields like a text input for keyword and radio 
button for filter in a form like this:

{% csrf_token %}

 Search 



All
Paying
Uploaded
Staff Pick
 


This form is displayed by a function which inherits generic View class, 
from its get method.

class Home(View):
def get(self,request, *args, **kwargs):
return render_to_response('items/search_page.html', 
context_instance = RequestContext(request) )
def post(self, request, *args, **kwargs):
print 'in home post'

What puzzles me is that when i am trying to submit the form data via ajax 
call (on same page) with jquery when someone clicks on search button, it 
takes me to post view of Home and not on to other function i have defined.
The javascript on the html page is:

   function search(e) {
e.preventDefault();
search_for = $("#search").val()
rval = $('input:radio[name=fancy_radio]:checked').val()
$.ajax({
url:"/search/",
method : "POST",
data : { 'keyword': search_for, 'filter': rval },
success:function(result){
alert(result)
}
});
   }


why is this happening ? 

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.