Refresh a div of a Dashboard without reloading the entire html page

Asked

Viewed 406 times

0

I’m finishing my CBT and I came across a problem. I am creating an administrative control panel and would like it to display in real time a Count from a table in my database. I was told that the ideal for this situation would be jQuery + Ajax... Someone would have an example solution of this situation to please go through?

Thanks in advance!

  • The ideal is websocket (after all, he was thinking for this). AJAX not the best option, but break a branch. If you are only willing to break a branch, you can use the function setTimeout of Javascript. This function will execute a certain code from time to time.

  • @Valdeirpsr sorry, but I have to disagree absolutely with your statement, depending on how you plan the system and what has Ajax will solve the case well, other thing, websocket was not made specifically for this, the use of it is broad. The situation is all relative, there is no way to say that X is better than Y, it will depend on case by case, system by system, resources that the hosting provides and the experience with treating data, I’ll tell you about a system I created, is a back-end "pushs" system [...]

  • [...] basically each user has a timestamp-based flag saved in a proper log file so I have 2 ajax, one that only checks the flag, ie does not use database does not return complex data, returns only 0 and 1, if you return one then an ajax to load the data of a specific table will be reloaded, that is to say the consumption is minimal, the requests in the database are also minimal and I also take advantage of HTTP cache (use the flag to ignore the cache if there are changes), plus I also use the HTTP response "304 not modified" (which is more complex)

  • For being a simple situation I must use setTimeout?

  • @Guillhermenascimento The protocol websocket is basically a two-way connection with very short response time and a better optimization than XMLHttpRequest or Fetch. Even one of the reasons for the creation of the protocol was due to the abuses committed with unnecessary requisitions¹. I agree with the statement that there is no better or worse technology, and the implementation is more complex. Note ¹

  • @Ericklimafigueiredo In these cases yes. (Example: https://answall.com/a/277307/99718)

  • @Valdeirpsr is exactly bidirectional, so uploading a DIV isn’t exactly a complex need, don’t you agree, now if it were a chat system or an online spreadsheet or text document with many people editing at the same temple, would make sense of the use of Websocket to even solve the "competition" of edits and multiple accesses that would cause things like cache could not be used, in this case not that it is better just for being, but could create something more efficient and even simple using websocket.

  • Thank you all very much!

Show 3 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.