Django-Ajax Issue
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:
<form method="POST">{% csrf_token %}
<input type="text" id="search" name="keyword"/>
<button onclick="search()"> Search </button>
</div>
<div>
<div>
<input type="radio" name="fancy_radio" value="all" checked='checked'/>All
<input type="radio" name="fancy_radio" value="paying"/>Paying
<input type="radio" name="fancy_radio" value="uploaded"/>Uploaded
<input type="radio" name="fancy_radio" value="uploaded" />Staff Pick
</div>
</form>
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:
<script type="text/javascript">
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)
}
});
}
</script>
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+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.
For more options, visit https://groups.google.com/groups/opt_out.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home