On Monday, August 4, 2014 12:12:43 PM UTC-4, G Z wrote:
>
>
>
> I don't understand why this isn't working any suggestions?
>
This probably seems like a django issue, but it's not.
When you submit a form, the current document becomes old news. Browser
posts the form data and waits for new page to be returned. Logically, what
you've written makes sense, but the side effect of the current document
becoming stale, defeats the logic.
$(document).ready() django isn't sending the page until your query
finishes executing, so you're probably left viewing the stale page until
the browser receives the new.
A kludgey method to convince the browser to show the <div> before the page
goes stale...
$('#queryForm').on("submit", function () {
if ($('#loading').visible()) { //if #loading not visible show it,
prevent default, set timer to re-submit.
return; //submits form.
}
$('#loading').show();
event.preventDefault()
setInterval(function(){ $('#queryForm').submit() },1000);});
Won't guarentee it'll work, but it should..
The professional method to achieve the desired effect is a bit more
involved.
To achieve the desired effect, use ajax to an url that returns json
response, which is a bit involved to setup.
Basically, you use javascript to issue an ajax call to another url which
loads data from the query. At the time of the initial ajax call, you show
the #loading <div>
When the ajax call receives it's response, you hide #loading and display
the json data in another <div> where appropriate.
The ajax call doesn't load a fresh, it fetches json data. json data is
more compact than html, so this has the side-effect of transferring
faster. Less work for the web server and less traffic between server and
browser. However!!! This requires more preparation.
Try the kludge, it might actually work. Then invest time implementing an
ajax solution.
--
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 [email protected].
To post to this group, send email to [email protected].
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/91d02524-f382-4afb-8ac4-f367d7536dff%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.