Skip to content
Advertisement

How do I make an ajax call perform a function only once

Basically, I am implementing a food status tracking for an order based on orderNo. I refresh the page every 60 seconds, to append the new status in my div. However, for the start as the order is placed, I have a ‘waiting’ status. I don’t want the same status to get appended to my div every 60s before the status is changed by the admin. How do I achieve that? Also, is it possible to have the appended statuses if I open the page after a while? For instance, if status=’Preparation’, I want to have ‘Waiting’, ‘Confirmed’ to appear whenever I open the page. Thanks

JavaScript

In my action.php file

JavaScript

Advertisement

Answer

JavaScript
JavaScript

Assuming that you are updating the same cell every time, this is what you can do:

JavaScript

You can clean up the code the way you want to, idea is to clean the div and append all the data.

Another option is to show all the status in front end and disable the pending status, then get the current status and enable the status that are supposed to be completed like, if status is preparing it is obvious that is has been accepted and confirmed.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement