-2

Basically I have a web page that creates reports for my company, the only problem is that the request sometimes takes up to one minute because there are lots of calls and it takes time to elaborate all the data. So , I'm trying to render a little bit user friendly the situation and I'm wondering if it's possible to make a Jquery function that will show my gif image when I send the request and waiting for the response to redirect me to the report page. I'm using Java with Springboot and freeMarker templates

Thanks

  • 1
    Yes, it is possible. Have you tried anything (googled something like javascript api call loading image, for example)? – Reinstate Monica Cellio Aug 03 '18 at 08:14
  • Sure I've tried some simple ones using $(window).load function but it just blocks my landing page, I'm wondering if there is a way of telling jquery to execute some code while processing a API request – Danut Andres Aug 03 '18 at 08:15
  • You need to include all relevant information in your question, otherwise it's just a code request and therefore a **bad** question. Show us what you've tried (in the question, not a comment) - read **[ask]** to see how to ask a good question. – Reinstate Monica Cellio Aug 03 '18 at 08:18
  • You are right. Thankfully I've managed to sort it! thank you – Danut Andres Aug 03 '18 at 09:15

1 Answers1

0

If I understand you right in your comment, you can hook into global ajax events: https://api.jquery.com/category/ajax/global-ajax-event-handlers/

Example in this post: https://stackoverflow.com/a/32538644/10167819

  • So if I got it right ,Sending a request with my java backend, Jquery will register it as an AJAX request. I thought that ajax request were Jquery only.Thank you for making thinks a little bit clearer – Danut Andres Aug 06 '18 at 08:45
  • Sorry, I do not really follow, could you elaborate? The thing is that I do not know how you could possibly send a request using your backend unless you are using JSF, that in fact, still generates appropriate AJAX calling JavaScript in the background. Every request that takes place on your page without reloading it is probably AJAX request(though there are SSE or other technologies now too). The code I pointed you to simply listens for *any* AJAX events happening and executes your code then. It is commonly used for spinners or loading bars. You can hook into individual $.ajax functions too. – kpolszewski Aug 07 '18 at 22:31
  • Second thought, if you are thinking about adding a spinner to redirection action that takes some time because of background actions(and not the AJAX request) you can simply add some $('spinner').show() to button that invokes that redirection. That is all I can say with the information you provided. Hope I helped you somehow. – kpolszewski Aug 07 '18 at 22:35
  • That's exactly what I did, I simply added to the button that sends the request the function div.show , I will try using $AJAX , I haven't been too clear, my program runs, springboot with java backend, so the request comes from the frontend of my spring templates. – Danut Andres Aug 08 '18 at 07:34