[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

ajax noob here I have a web page which cycles through images

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 7
Thread images: 2

File: 1485626596568.jpg (84KB, 712x850px) Image search: [Google]
1485626596568.jpg
84KB, 712x850px
ajax noob here
I have a web page which cycles through images and I want it to go to the next one when you press the next arrow - how do I handle showing new images if someone uploads an image while the user is already on the page?


>home.php shows an image
>press button for next image
>someone else uploads an image
>how to include new pic in the flow
>>
One option would be to consistently poll the backend for a list of the images stored in there. If there's a timestamp attached to each image, it'll be quite easy to see if more images can be shown.

Second option that comes to mind would be to utilise web sockets. Send the information of the new image to all the clients.

Or then you could implement it so that each time you press the arrow, it fetches a list of the images and then loads the image following what's currently being shown.

Many options, each of them is useful in their own way, largely depending on your use-case.
>>
File: 1478528247004.jpg (879KB, 1345x1550px) Image search: [Google]
1478528247004.jpg
879KB, 1345x1550px
and what's the best way to let a user cycle through the content when new content is added constantly?

say they start at post 4 then go to 3, 2, 1, then a post 6 and five is added
it seems a bit resource intensive to have a cookie remember which ones they've seen
-
equally it will get annoying if they veiw all of the content in the same order (most recent to oldest), they might see content many times but next veiw the oldest content
>>
>>58911723
thanks for the reply

yes they all have upload date/time stamps recorded on an SQL database

I can see how it would be easy to show them all the pics in descending order then show the ones since they logged on in ascending but it will be for regular users who will check back for not just new but all UNSEEN images

I want it to show all unseen images before cycling through old ones - a bit like tinder except when you're done it lets you see old ones again
>>
Consider sending a state to the backend when fetching a new image.

In the scenario where you have images:
1, 2, 3, 4


And the user views 1 and 2, then image 0 is uploaded, if the client keeps track that the min-image seen is 1, and the max-image viewed is 2, you can check in the backend if there exists a newer image than 1 (which would be 0 in this case) and if it doesn't, pick the next one from the max-image sent by the client (3).
>>
http://php.net/manual/en/class.iterator.php
>>
>>58911673
Use jQuery.
Thread posts: 7
Thread images: 2


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.