2

I am trying to develop an application with Django. I have a form in my HTML file which will pass same data to the server. At server side, my python function(called submit) will receive the posted values and process them and then redirect the user to a new page.

Question: How can I show a loading gif to the user until my python function is processing posted data and finished? I searched on the stackoverflow about this question and there are some answers (this and this and this) but the answers are for finishing Ajax functions, or there is no explanation how can I identify when my python function has been finished or is for flask framework.

Any help would be greatly appreciated.

Community
  • 1
  • 1
Stateless
  • 293
  • 2
  • 4
  • 18
  • 1
    Since you are not using AJAX, just show the loading icon when you submit the form - when the server-side function finishes it will redirect the user to another page, right? Using jQuery it would be something like `$('#id_gif').show(); return true` in the form's "onsubmit" event. – Paulo Scardine Apr 29 '17 at 12:15
  • Yes, I am not using AJAX. But in my form, I have mentioned my python function name on the server in the submit event to handle my posted values! How can I mention $('#id_gif').show(); return true in the form? I think I should mention the python function name in form's action attribute and $('#id_gif').show(); return true in form's onsubmit event, right? – Stateless Apr 29 '17 at 12:20

1 Answers1

2

This is rather simple. First you will have to download font-awesome.css from here http://fontawesome.io/.

Then create one element like <span class="fa fa-spinner"></span> this element will be hidden by default. Set it visible at the beginning of your ajax call and hide it once you have receive the response.

If you want to show your own image, the logic should be the same.

osmay88
  • 421
  • 3
  • 12
  • Honestly I could not understand your answer @osmay88! I have not worked with fontawesome at all and I think I do not need to learn that at this moment. My question is that how I can call my python and my javascript function from my form in a way that until my python function is processing my passed values to the server, my javascript function shows an icon or gif to the user? Do you have any sense about that? – Stateless Apr 29 '17 at 13:28
  • When I wanna use it in a html file, there is a ongoing gif which by default is whowing to me! I can't find anything about my question in your giving link! Where is python function calling dude? – Stateless Apr 29 '17 at 14:19
  • I mean I can trigger a function at server via
    . But as this form will be submitted, I need to call a javascript function to show a gif t user. And then, when python function finished, I wanna to redirect user to a new page. Right now, I can trigger python function, my problem is that I have no idea about calling javascript function.
    – Stateless Apr 29 '17 at 15:03
  • No, instead of posting from using the form, post using jquery submit. So you will override the default html post and use jquery. – osmay88 Apr 29 '17 at 15:04
  • Check this https://plnkr.co/edit/GY8wz3eZJBqxsr1JudnT?p=preview and try to understand the logic. Read the js file – osmay88 Apr 29 '17 at 15:12