For example: i've changed "user balance" in my database, how to update this value direct on client side. So my client in this case see that change immediately.
I don't like to do it with jQuery since it will be slow with required speed and will makes some performance troubles.
a website called blockchain.info does that somehow, maybe he is using websocket.
BTW I tried to use Ratchet webSocket but I don't know how to link each connection to specific client.
Any help would be appreciated, ask me if you have any questions.
If it is a new project, try using the meteor framework, but I don't know if such a drastic change makes sense for the size or stage of your project or the criticality of your requirement. Meteor is very good for "subscribing" to changes in data and updating the view based on that. In fact, it is very trivial in meteor. However, moving your entire application to meteor may not make sense, only you can decide. Check out https://www.meteor.com/
I commend your dedication to efficiency. Maybe take a look at this site to see if thats what you're looking for.
AJAX with Vanilla JavaScript
Related
I'm starting a project to create a front end and back end API that updates in real time.
I was thinking of making something like a Forex "viewer" of sorts using https://www.coinapi.io my only problem is, I want to make the server and everything and have it fetch data from that api, put it in my own DB, and have the frontend update in real time (i.e. a price drops, and it instantly updates without really a refresh).
I'm wondering if something like this is practical. I think its a great idea and I'm super interested in this.
I guess I would use websockets, but I don't know the first thing about that, my experience is with REST API's.
Any ideas/thoughts would be nice.
The frameworks and resources ill be using are:
Bootstrap
Vue.Js
Chart.Js
Node.Js
Express
CoinAPI
MongoDB
Mongoose
I think Express and Socket.io would be a good solution here. They work really well together and you would have crossbrowser checks and a lot of stuff you get with Socket.io out of the box. If you would use your own WebSockets you would have to write all this stuff, which is also a good thing if you know what you are doing.
It can work really well and fast, of course it always depends how well you write your code. But the idea will work fine.
Here you have a beginner friendly tutorial for socket.io:
https://www.youtube.com/watch?v=tHbCkikFfDE
And here is one with MongoDB: https://www.youtube.com/watch?v=8Y6mWhcdSUM
I have a question I tried googling but couldn't get what I was expecting. Hope people around here will make me clear.
Am working on AngularJS from last few months and now I have a situation where there is a list of data. This list is loaded via a server(PHP).
Each list has a tracking image which changes according to the status set in the database.
Now I want this tracking image to change when the admin changes the status of that list in the database.
Right now it happens when I reload the page or when I go back and come again on this listing page.
I know there is something called $watch and in js we have setInterval.
But is this a good idea to use $watch or setInterval as it will check continuously in the database for change. Am just wondering if this will lead to the crash or it will make my application to get slow.
Please note am developing a PhoneGap application using AngularJS.
Please throw your ideas it might be helpful. Thank you
Well, this is probably not the right place to answer your question but there is no problem in using $watch in AngularJS.
But, using setInterval and continuously polling your server will be expensive and is a waste of resource. You should probably go for the something called WebHooks.
Resources:
https://en.wikipedia.org/wiki/Webhook
http://www.webdesignermag.co.uk/automate-mobile-app-development/
Since you are developing a PhoneGap application, you can also use the Push Notification concept of Android and iOS.
If you want to let the server update your client, without the client repeatedly asking for it, then you will need to use websocket libraries. If your server is not able to supply a websocket service, then i fear that doing a $http.get every certain timeperiod is your only option. But yes it sucks, because of the often unneccesary data travels.
My question is,
If there is a way to detect (maybe an event) - if a user that browse to my web, has change my html/js code?
My goal is:
for example:
To detect if someone has change my value that containd in <input></input> by the code.
Or change an array that he found in my js that holds parameters
And if i will detect that he change something? he could not still using my web (in this session) until he refresh the page and get the authentic files again (without changes).
Unfortunately no, unless you are using javascript to send data to a server you have than you could possibly include some sort of checking. However that is not possible with client-side javascript.
If you use something like Node.JS or similar you could have the javascript on the server-side and you could insure that it does not get altered.
Sorry, I hope this helps.
The anwser is YES, you can, but only the HTML:
To do this you have to set an interval to read all the DOM and then send it to back-end (where you have the initial state)
You can't do this if there is a lot of DOM manipulation done by the JS (SPA apps). I mean, you can, but it's overkill
This is overkill
There might be other methods to think about just for the love of a challenge but I don't see a practical reason to do this (There might be one but who cares about that).
All cross-browser issues are also addressed :P
I get some data from a page abc.html using Ajax and I store it in a table.
Once the data get stored in the table(i.e. commit takes place), I want that data to be updated in the page xyz.html in runtime so that the users can see the updates without having to refresh the page.
I have got the data and updated the data in the table.
But I don't know what to do once the data gets stored in the table.
I believe ajax is required to update the webpage xyz.html.
It would be of great help if someone can point to a resource on what approach to follow to implement it.
--Update--
I am a newbie but I am not asking anyone to write the code for me. Thanks.
You are going to have to look into something like Socket.IO for real-time updating.
http://socket.io/
Basically, socket.io is a javascript library built on top of Node.JS that constantly trolls a servers looking for new activity. This is sort of ajax, but an ajax request is normally prompted by a user (by a button click or scrolling to the bottom of the page, for example).
I'm not gonna write the code for you. If you are new, it's not going to be an easy thing to accomplish. This may seem like a simple feature, but it's actually quite complex.
If you start writing code, and get stuck, come back and ask a question, but no one is going to write this feature for you for free buddy, sorry.
Here is a tutorial on how to write a real-time updating chat-application with Socket.IO. Take some time and get to know how Socket.IO works and you should be able to figure out how to make it work for your needs.
I want to create a notification icon with Dojo, but I'm not sure where to start.
The icon has to be similar to those found on Facebook and Whatsapp, showing how many new messages/notifications you have.
I've been looking in the Dojo reference, but couldn't find a good widget to use. Maybe I'm missing something obvious, but I might as well ask it here.
Googling hasn't been of much use unfortunately.
As far as I know there's no widget that automatically does the stuff for you. This problem is far too specific to provide a general widget for it. You also have to think about several things before you can start.
Do you want to use WebSockets? The web is generally made for pulling content, if you want to push your notifications from your server to your client, then you will need to look at WebSockets. A good tutorial to use them can be found on Sitepen.
If you don't want to use websockets (you're not able to create a websocket server or you have some other reasons) then you will probably have to use a simple "REST service" and obtain the amount of notifications from it. This means you're script won't be "live", so you will need to pull the content from the webservice every X seconds/minutes. This means you need a normal AJAX request which can be done with the dojo/request/script module.
If you need to time this AJAX request, you can use the dojox/timing module.
This is only the "logic" part, the user interface (icon + # notifications) can be made by yourself with plain HTML and CSS.
What about dojox/mobile/Badge:
http://livedocs.dojotoolkit.org/dojox/mobile/Badge
?
From comment:
"Maybe you can find something in the DojoX library" -
off course you will find much.
I would recommend
dojox/socket
see http://dojotoolkit.org/features/1.6/dojo-websocket