I am creating a social networking site using php,jQuery and MySQL. I have a big doubt. How to dynamically update a user's home page when one of his/her friends does an action and if that has to appear on current user's page as soon as the friend has updated. I am new to this, please help me in this problem?
It looks like you're looking for a way to implement push functionality from your web server to a current user's page.
The push data will be sent as part of a friends' action or soon after (in a queued fashion), and once it arrives to the client Javascript should be used to update the view.
Some methods of doing that are described on the push technologies Wikipedia page.
You can add a JavaScript timer function in web page side. And regularly to check whether new information is gather.
If there is information, then add new information in the page or notice user.
This is a jQuery Timer.
This is function of jQuery.ajax(). You can use this function in jQuery Timer to check whether there have new information.
If there have new content, you can use "Adding elements to the DOM" to display them out. This is a reference for this topic, Adding elements to the DOM.
I think this way would be helpful.
Related
I'm sorry if that question seems vague but here's what I have.
On the side of my webpage I have a chat script that performs the following functions each and every time the page is called up.
Connects to my BOSH server
Pulls data according to who is logged in
Displays the user's roster on the sidebar
I'm trying to save bandwidth (also prevent the user from being logged in/logged out each time they move pages) by keeping the chat window open on the side and using a frame concept to load the other data, similar to how Facebook does things.
I'm aware of
history.pushState({},"New Title Goes Here","http://facebook.com/Something");
but I know there must be something more to it. Just a little lost on where to start looking. AJAX I know if going to play a big part of it, but I don't like to rely solely on javascript all the time.
Any help is appreciated, thanks.
sorry if this is a little late but you can use Strophe's attach function so that your BOSH session will not be lost in between page reloads.
What you need to do is first, connect and authenticate to your XMPP server then save the JID, RID and SID where it wont be lost when your page refreshes. In your session or a cookie for example.
var conn = new Strophe.Connection('your_bosh_url');
conn.attach(your_jid, your_sid, your_rid, function(status){
if(status === Strophe.Status.ATTACHED){
*and so on ...*
Have a content div and a chat div. My website uses AJAX to just be nice, so I have a nav div and a content div, and I load things with jQuery. Take a look at my site: http://derek.genevievehoward.com/ and this JSFiddle http://jsfiddle.net/howderek/tNVd8/
For some reason JSFiddle doesn't like the AJAX, but my website uses the same javascript, so I can assure you it's accurate.
I am using a php application. Here many users can login at same time like a web site.
Here a want when a user is saving form , a pop up should automatically appear on the browser of another user. id of 2nd user will be mentioned in form , when 1st user is savinf the form.
Please any body give me any idea.At least what type of technique i should use and what type of technology is required.
Thanks !
Rakesh
The technology you need is AJAX.
You should write a javascript function that calls periodically your server (through XMLHttpRequest) for any event you want to notify to your user,and when you have a relevant answer, that same function should pop up the warning.
You'll probably want to start using jQuery, a wonderful Javascript library (that includes Ajax calls) that will save you a lot of time.
i have a master php page and now i am loading different pages in a div of this master page using ajax. now i want to add a back button on the slave pages so that the div can loaded with its just previous slave page but the back button, i am using uses history.go(-1) that take me away from master page. has anybody any solution. Thanks in advance.
the code i am using is written below. but it is not working in ajax pages
Go back
My suggestions would be to use a framework for this purpose like backbone.js
Where you can setup routes just like on server side.
I feel this is the best way to do this on ajax sites.
Read tutorial on Manipulating browser history.
It mentions:
pushState, which is used for creating "entries" in the browser's history (with attached data about state), allowing to get back to some specific state you previously saved,
onpopstate event, that is fired when you go back or forth through the browser's history, and passes information previously saved for specific entry in the history (so you actually can read data previously saved by pushState for this specific entry),
In case pushState and onpopstate do not work for you, there is still some ability to work on the basis of onhashchange event (however limited).
The good news is that what you want to achieve is definitely possible. It is even implemented in many famous sites such as Twitter, GitHub, Facebook etc.
You can use the history functionality provided in newer browser. There is several libs that already provide functionality for you:
For JavaScript MVC applications:
http://documentcloud.github.com/backbone/#History
For mobile web pages:
http://jquerymobile.com/demos/1.0b1/#/demos/1.0b1/docs/pages/docs-navmodel.html
For implementing a solution your self:
http://benalman.com/projects/jquery-hashchange-plugin/
I'm trying to build an chrome app/extension for my website which is mostly a mybb forum. I am wondering if anybody knows how would I check to see if a user has new Pm's or maybe new posts on his thread? Maybe by JS, AJAX, or PHP
As far as events go, generally for PM's there is a field in the database called 'read', which is false if they haven't opened it, and true if they have. On a page load, check to see if there are any messages to the user that are 'unread', and if so, load them, and use JQuery to make a pop up saying a short description of them. You could also have a small AJAX script periodically check for this.
As far as new posts go, the traditional way that I've seen it done (but by no means the best way) is to keep a timestamp of when a user last visited the site. On page load, get every new post/topic that was created after that timestamp, then serialize this data and store it in the database, or in a cookie (if this serialized data already exists, unserialize it, merge the two and reserialize it). If a user visits a topic, get all data from the serialized entry that matches (IE, in the same topic, or the post number) and remove it from the serialized data. Then again on page load or by using an AJAX script, check periodically if they have an 'unread' post on a topic that belong to them (IE, created after their last timestamp value), and use a bit of JQuery to notify them.
Learn JQuery. It is a very friendly javascript framework and you will be up and running in no time. Coding in JQuery is fun!
Do periodic AJAX request.
inject data into DOM or maybe if you are creating a Google Chrome Extension like your tag is telling use the awesome Desktop Notifications System.
For my next application i would like to implement something that has a feature like the facebook wall but let me explain a bit. For those of you who used facebook you know that when somebody posts a message on your wall, and you are logged in to your account, you will get a notification immediately somewhere in the lower left corner. Lately they even pushed this a little bit further and if somebody comments on it the comments are updated as you visualize the page, it's like an instant chat.
My application will be developed in PHP, I will use Zend Framework to do it. I'm interested in the basic principle that makes the facebook wall behave like that (updates in real time). I know there is ajax involved but I can't really tell how is the javascript triggered when the user is doing something. Or even more, how to push back to a user some info that was added after he viewed the page. For example, let's say that a somebody adds me as a friend. I would like to see a notification saying "X has added you as a friend" if i am logged in. I hope you understand what I'm trying to do.
If you can tell me some basic ideas, maybe provide some links that have this information I would be very grateful.
Thank you for your time in reading this.
you need to look at comet , reverse ajax , ajax polling
If some event is triggered, then store the event on database (with ajax or without ajax).
You will be needing a script in server to check if some event has been triggered or not. This script should be able to check events that are stored in database.
You need to execute script in step 2 periodically. This can be acheived with with ajax (javascript or jquery) and a function settimeout (on javascript) to send ajax request to server periodically.
Changes are sent from server. So parse the response and update in page using javascipt and jquery.
So, it can be summarized as
Register an event (for one user)
Check the event (for other user)
Parse the response and update the page
There are several elegant ways to do this as answered by others.
The best would be the start the project and ask for help where ever stuck.
It is only partially possible to keep an HTTP connection open, so the best option is probably to poll for changes. You can send a request each second to see if anything is changed since time 'x'. On each response you send along the server time. With the new request you send the time of the old request and the server can return any events that happened inbetween.
Also you can read something about AMQP. You can send a message to recepients inboxes (after some actions in your system) and then read inboxes after start or with some time interval.