Refresh chatbox without refreshing page - refresh

I'm working on a chat application for my website and everything has been coded (in php).
But I need the chatlog to refresh (once every second or so...) how can I do this?

Related

How to use django signals to refresh a specific page

I am creating an ecommerce webapp and I want to update my admin page when user place order. After research i found out about Django signals, but it seems pretty confusing. The idea behind this is that, when a user places an order I want the admin page to be refreshed and show the latest updates. I tried ajax but javascript can only work with the current open page. Can anyone help me with usibg django signals this way?
I think you misunderstand a little, if your idea is that the admin page viewed by the user in a browser is to be refreshed. The page viewed by a site visitor is retrieved on demand of the browser. The user could refresh a page, or a page script may auto-refresh on a timer (this is not a very good solution, but it is easy).
Django can't make the browser update the page.
Signals can cause django to do something in the backend, but they can't solve the problem that the browser is in charge.
There is one technology designed to allow the server to push content to the browser: websockets.
If you use websockets (Django's fairly recent built-in support is called Channels (https://channels.readthedocs.io/en/stable/)), then you can push content to the browser, where a receiving script on the page will do something with it. This is a very powerful technique, but there is a learning curve of some hours if you are starting from scratch.
Recently I came across this front-end library which tries to make this easy as
far as the browser goes: https://htmx.org/docs/
But you still have to deal with running a websocket server and learning how to send messages to a websocket. You will however feel like a superhero at the end of it, so there's that.

Facebook Page Webhook stopped working. It was working from last 1 year

We have configured webhook in facebook app earliear.
After subscribing the facebook page we were able to receive real time update on our server from facebook page.
Now webhook was stopped working.
We are not getting any real time update for new post from facebook page.
We have pre-configured setup as per bellow guide:
https://developers.facebook.com/docs/pages/realtime/
I'm able to view that my page has installed my app by using bellow sample api:
GET graph.facebook.com/PageID/subscribed_apps
But not getting real time update
Any help will be appreciated.
In general, if a webhook stops working: For Remove the webhook, and then add it again. (This helps in most such cases. Facebook will stop sending updates if your endpoint is too slow to respond or responds with errors over a certain period of time.)
One thing to add,My facebook app is not live but it has been working from last year.
If you want updates from a “live” page (as opposed to one created by a test user), you need to set your app live now as well.
Previously apps in dev mode were mostly unrestricted, but with the current changes in light of Cambridge Analytica, they changed that.

What could cause a Django based Facebook Page Tab to take 2 minutes to load?

I have a very simple web page that uses the Facebook Javascript API and is installed as a tab on a Facebook page. When the page is loaded, the only thing it does after calling the usual Facebook init code is to listen to auth.authResponseChange and then show/hide various elements depending on whether the user is logged in or not.
If I load this page, via http or https in an ordinary browser session, everything is fine. The page loads reasonably fast.
But if I load the page tab in Facebook, it hangs for about two minutes. Chrome tells me that this wait is due to 'waiting' for my page. But if I watch the access log, I don't see an access request logged until just before the page displays. So it seems like Facebook is masking what is really going on behind the scenes.
I opened a ticket with Facebook, and they replied that this issue was due to my code and reproducible with any POST that contained a signed_response.
After much head scratching and experimentation, I found that adding the following two lines to the view that handles this page fixed it:
if 'signed_request' in request.POST:
pass
So clearly Django 1.3.1 is holding the HTTP session open until you actually read some POST values. Ouch.

What if you put a manifest="cache.manfest" in a .cfm page?

We're developing a tablet app, and my coworker had a rogue thought:
What if you put a manifest attribute on the html tag of a ColdFusion page? Would it
still work if the user couldn't get to the server?
I think it's lunacy, but I wanted to hear what you guys had to say.
The client side is not aware of how is generated the page. He didn't even know if the page is generated. So, the page is cached like another page.
If you are not connected, the could handle this case with some javascript and alert the user you can't communicate with the server.
You could simply disable the application or work with localStorage etc...

FB App opening in new browser rather then FB Canvas if I use DJango Fandjango App

I have a FB App which I created using Fandjango. It works fine if a user logs in to the application for the first time but in case user has used the app earlier and want to open the app, it opens up in independent browser and not in FB Canvas.
Any Idea how can it be corrected.
You're seeing this behavior because Fandjango caches the signed request in a cookie so you don't have to proxy every request through the Facebook canvas. There is currently no way to disable caching because it would introduce a very large overhead (several seconds per request) and make it very difficult for you to redirect the user to various parts of your application.
See https://github.com/jgorset/fandjango/issues/55.