0

I'm trying to make an app that triggers different content on a webpage based on the button pressed in the app. I need to be able to send a parameter to tell the server to refresh the video, image, and text when a button in the app is pressed....right now it changes the video/image but you have to hit the refresh button in the browser to see the new content...

Everything I've tried refreshes at an interval and it reloads the video/content repeatedly...

Currently i have 3 entries in a mysql db, and one of the fields is "active". When I press a button in the app, it sets all of the row's "active" field to 0, then it sets the record with the id of the button pressed to active=1.

In my display.php page I have it check the mysql for all records with active=1, and it works great, but I need to somehow tell it to trigger a refresh when the active record changes in the db....

The webpage will only be run one 1 machine which is running chrome, it's then displayed on a digital billboard, and I want people to be able to trigger the different content by pressing different buttons on their mobile devices...I can't figure out how to communicate with the sedna presenter software to tell it to refresh the page so was hoping to just make the webpage update itself (like with ajax but for video/image) and the sedna simply displays the webpage like a view in MVC pattern.

Would an iframe help?

user1108224
  • 159
  • 1
  • 14
  • I think your looking for AJAX ... have a javascript poll the php script for an update .. Their is now way to push new informtion from the page that i know of other then this though i'm aware of .. Might be possible with SOAP but i don't know to much about it – brendosthoughts Jun 20 '13 at 16:18
  • with edit: no an iframe would not help ... iframe's are rarely the answer to anything, ajax will work for images ,as for video a flash player script would make this possible (not sure about ajax) – brendosthoughts Jun 20 '13 at 16:21
  • hrmmm I got it to load the page via ajax but you have to click a link to trigger the switch, any idea's on switching it with a url+parameter to trigger the onclick? – user1108224 Jun 20 '13 at 16:28
  • can you clarrify that? ... you can use a javacript to run a request to the server (your php script) like this `window.setInterval(function(){ /// call your function here }, 100);` the 100 mean's poll the server ever hundred mili seconds, is that what your looking for? – brendosthoughts Jun 20 '13 at 16:32
  • not quite because it refreshes the video repeatedly every 100ms, otherwise it would work... – user1108224 Jun 20 '13 at 16:37
  • Okay ... you need to seperate the logic on server side (so that you can check for an update without reloading the page) and then if there is an update refresh the page – brendosthoughts Jun 20 '13 at 16:40

1 Answers1

1

So basically your going to want to add a new php script on the server which looks for the change in your mysql table on the field active (as an aside there is a better way to do this then repeteadly checking though I can't recall how). Then have your javascript function poll this script. using this method again:

  window.setInterval(function(){ /// call your function here }, 100);

Have the php script return a 0 or a 1 to indicate if active has changed. then check this result in your java script if active has changed reload the page with a get request to the display.php script ... if you want some help with the code I can post somethng in a bit... I'm just eating lunch and on a mobile so it will take a bit of time

brendosthoughts
  • 1,645
  • 4
  • 21
  • 36
  • If I had a second php script, I could send a url+param to it at the same time I send the url+param to the other script to update the mysql. But what to put in the new php to say "refresh other php"...any idea? – user1108224 Jun 20 '13 at 17:25
  • As I said this will be handled by the javascript (just send a string) yes or no will be sufficient so if you want to update have the php script `echo yes` then read this result in javascript and `if(result="yes"){send get request to display.php}` – brendosthoughts Jun 20 '13 at 17:34
  • hey< if your server and web page ("client") are far apart (geographicallly or an a busy netwrok with multi hope etc..) and hence the "round-trip" time is fairly long for your acceptable update this method might not be acceptable If this is a case look into COMET or reverse-ajax http://en.wikipedia.org/wiki/Comet_(programming) ... and you may be able to improve it slightly at the least (sorry, just found this now!) ... here's the S.O. thread on it http://stackoverflow.com/questions/19995/is-there-some-way-to-push-data-from-web-server-to-browser. if you need more help you know where to find me – brendosthoughts Jun 20 '13 at 17:42