I'm building a search function with Jquery and Django. And Im wondering how I combine the jquery .load function with a form submit.
This is what im working with.
I click a link which open a dialog box, loads a child template with a Django form for search.
<form method="post" id="searchform" action="/search/">{% csrf_token %}
{{ form.as_p }}
<button type="submit" id="submitsearch">Search</button><p>
</form>
This function works great if i just redirect to a new page with the search results that i get back from my Django view when the form is handled.
But when the searchform is filled i want to submit and get the results back in the same dialog. I'm thinking something like this (but this is not working)...
$("#dialog").on("click", "#submitsearch", function(event) {
event.preventDefault();
$("#dialog").load('search/' + $('#searchform').serialize());
Is it possible to use the ".load" into the dialog and submit the form at the same time? How?
Thanks!
Copyright Notice:Content Author:「user3199840」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/22108177/submit-django-search-form-and-use-jquery-load-for-the-results