ueon Posted June 24, 2011 Share Posted June 24, 2011 If a user has loaded a website, and doesn't click on anything. However, if an administrator changes a value on the server that affects the page the user is on, does the user see the change immediately or after a refresh? this is an php/ajax website Quote Link to comment https://forums.phpfreaks.com/topic/240326-retrieving-data-from-server/ Share on other sites More sharing options...
gizmola Posted June 25, 2011 Share Posted June 25, 2011 The way browsers work is defined by the HTTP protocol. At its most simple, it's a request/response system. Browser requests page -> Server replies with response. This happens as quickly as possible, and as soon as the last bit is sent the server closes the socket connection, at least in a logical sense. Page requests occur in response to user activity (entering a url, clicking on a button or link) and by design there is no sustained connection or session possible. Cookies were the first attempt to provide a mechanism to get around this lack of session. At the point that a page has been delivered based on information pulled from a database, that information is inherently old. If one second later someone changes the database, there is no way that will reflected in the static html page I'm looking at in my browser. Ajax is a fancy name for what is a simply facility that was added to javascript (originally by microsoft) allowing it to make connections from the browser to the server using javascript code. So you can set up a connection to sit and poll fairly frequently, and in that case, you would be able to detect that data had changed and update the screen via javascript. There is also a technique people call "long polling" that takes a slightly different approach and in some cases is a better solution than frequent polling. This does a great job explaining it: http://blog.perplexedlabs.com/2009/05/04/php-jquery-ajax-javascript-long-polling/ Quote Link to comment https://forums.phpfreaks.com/topic/240326-retrieving-data-from-server/#findComment-1234541 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.