Reputation: 95
I have to access data from MySQL database which is updated dynamically without refreshing the page. Example: A user requests a service and the details are stored in the database. When the admin accepts the requests it should be updated from pending to accepted on the user's web page without him refreshing the page.
Upvotes: 0
Views: 213
Reputation: 832
This can be accomplished by Ajax, but you need to query in intervals to see if data has changed. A better approach would be, if you have access to CRUD methods in your codebase, then write a trigger that whenever CRUD operations happen, you will call the web service to refresh the page. For example, Consider GIT , when ever you push a change, if anyone looking at the pull request will see a msg that it is outdated and needs to be refreshed
Upvotes: 0
Reputation:
This can be accomplished by using ajax.
Since you did not provide any code or a detailed explanation of the enviroment you want to implement this in i can't help you with the specifics but i can point you in the right direction.
the easiest one is using jquery and its ajax api. Link to jquery documentation
But since i do not see jquery tagged in this question i assume you have your reasons not to use it. The best alternative. in my humble subjective opinion is Axios Link to Axios github page
you can also use the native XMLHttpRequest [backwards compatible with older browsers] And fetch native api's. but these are harder to implement as a beginner.
Upvotes: 1