Nov 21, 2009

How Can I Make An Auto-updating Shoutbox Type Script? - I have a few ideas involving AJAX but im looking for something more..

free web hosting
Open Discussion > MODERATED AREA > Computers > Programming Languages > Others

How Can I Make An Auto-updating Shoutbox Type Script? - I have a few ideas involving AJAX but im looking for something more..

shadowx
Hi all.

Ive just started to experiment with AJAX working with PHP and MYSQL to get data and display it and im looking to implement it into a shoutbox similar to the one here on the forums but i have a question...

i know how to use ajax and JS to refresh the contents of a DIV every few seconds r so and that essentially reloads the shoutbox content as the REFRESH button does up there ^^ on the shoutbox but i think it silly that it should update every few seconds even if theres no new activity so what im looking for is a way of letting my AJAX know when there is a new entry in the DB and then reloading the DIV to show it as a shout.

One way i just thought of is to use PHP to detect if a new entry has been made, if it has then i will echo out a variable containing the complete entry and if nothing has happened then i can echo out a variable that basically says "no" and have my AJAX detect that and not change the DIV. the downside is with all this AJAX loading the php file every few seconds server load wouldnt be good and it also has a habit of slowing down the browser and lagging it every now and then, this leads me to the next question..

Is there a way to notify my AJAX via php and SQL of a new entry in the database without loading the php page, so instead of AJAX contacting the PHP it works the other way around?

 

 

 


Comment/Reply (w/o sign-up)

truefusion
In order to have the PHP script run, it has to be first called, of course. And in order for the AJAX to pick it up, it would have to be running at some kind of interval (of which the PHP script would be runned via cronjobs, whether or not there are visitors) to check the PHP script. This would not only put (extra) load on the server, it would also put load on the browser (however little it may be) of the user. On the version of my shoutbox that i'm working on (it has AJAX), i don't have it refresh at certain intervals, i just let the user click the "Refresh" link if they want to; the shoutbox will reload if they refresh the page or move to another page on my site. So i don't think what you want is possible: having PHP contact AJAX; for in the end it'll just be AJAX contacting PHP anyways and not the other way around.

Comment/Reply (w/o sign-up)

shadowx
QUOTE
In order to have the PHP script run, it has to be first called, of course.


True, i didnt think of that...

I was wondering how the T17 shoutbox works, is that interval based? Eg a user shouts a message and so many seconds later it is updated?

Comment/Reply (w/o sign-up)

truefusion
QUOTE(shadowx @ Aug 23 2007, 01:29 PM) *
I was wondering how the T17 shoutbox works, is that interval based? Eg a user shouts a message and so many seconds later it is updated?

The way i've seen it work is it refreshes at an interval and it refreshes after the user submits a shout; the interval and shout times don't affect each other.

Comment/Reply (w/o sign-up)

shadowx
Fair enough! It seemed to me as though it only updated as a shout was made but of course that was probably just because a user shouted before the update. Ah well i shall use my interval option then!

thanks

Comment/Reply (w/o sign-up)

Variablez
I would like this too for my site, welp back to searching!

Comment/Reply (w/o sign-up)

Nabb
If you're making a shoutbox, then you should make it so that when the entire box doesn't actually refresh, but instead it loads newer messages and some javascript should add them to the box. That way, you don't load the newest 10 (or whatever) messages every 5 seconds, and instead only use a few bytes of bandwidth (excluding headers and stuff tongue.gif) You could do this by sending a variable signifying the latest shout received, and then returning newer ones.
It could also help if when there are no new messages, the delay is increased, and when a message is sent or received, the delay is reset. Alternatively, you could do something like done here and disable the shoutbox after a period of inactivity (it's 10 minutes here).

Comment/Reply (w/o sign-up)

SofiaComp
i think that the user should make an http request to the server when he clicks enter or shout.
why you need auto-update anyway?

ps. i know how to use javascript but am not familiar with ajax

Comment/Reply (w/o sign-up)

TheDarkHacker
Check out my script www.ndvf.tk
That chat is mine using AJAX and PHP.You don't need to store messages in MYSQL,its more complicate that way,you could simple use one text file.AJAX request function should be called every 20-50 miliseconds...I used setTimeout("call function blabla",50); and the function will get responseText from the php page which gets response from the text file.It's small comlicated and normally for advanced users.I am using the ajax library instead of xml http request.

Ps: You can see my script from www.ndvf.agilityhoster.com/chat/chat.js
It is starting with that comment //startuvanje na chatot or it was //starting chat

Comment/Reply (w/o sign-up)

manish-mohania
@SofiaComp
QUOTE
i think that the user should make an http request to the server when he clicks enter or shout.
why you need auto-update anyway?

ps. i know how to use javascript but am not familiar with ajax


Let's suppose you are using the shoutbox; since there can be many users using shoutbox and not only you, you will want to know the messages sent by the others even when you are not sending any message. In this case you need the auto-update.

@shadowx, nabb

I have heard a lot about shoutbox feature, but It never occurred to me that it should run this way. It is very interesting to know this alternative viewpoint.

My solution (I do not know if it really would work tongue.gif), quite similar to Nabb :

In Ajax, we have two methods:
1. First method, which sends a request to the server.
2. Second method, which is called when a response is recieved from the sever for a request made to server.
As, it is an asynchronous call it is not necessary that second method will get called immediately.

What we can do is :
1. when a request to the server to fetch a new message is made, then it(server) should put the request in wait/queue mode and should not return the response until and unless there actually is a new message.

2. When a new message arrives then server should return response for all the pending requests which will get caught by the second method. Second method then should refresh the client window(or div) and then call the first method again.

I am not sure if 1. and 2. can happen, especially the 2; but I think in java we can use a single servlet that handles the request and use wait and notify method calls to get it done.

Earlier, when we didn't have the ajax; remember, we used to chat on yahoo using the java applet. I don't know how they used to do it, but if it can bring down the server load then why can't we build a shoutbox as java applet ... just a thought ??

 

 

 


Comment/Reply (w/o sign-up)



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

This textarea will convert to Rich-Text automatically (IE, Firefox, Chrome)

Similar Topics

Keywords : make, auto, updating, shoutbox, type, script, ideas, involving, ajax, im,

  1. Seeking Help With Javascript
    Need help with drag and drop type script (1)
  2. Browser Compatibility Problem With Firefox - Javascript + Css
    Having trouble making a script work right - any suggestions? (3)
    Hi, Im working on a website, and im trying to make a right-click menu, which opens on right click,
    wherever the cursor is, and closes on mouse out. I wrote the code below, and when i ran it in IE it
    ran fine, just how i wanted it to work. However in firefox, the menu just opened in the top left. im
    presuming this is because it doesnt like my style changing in the javascript. Any ideas, and
    suggestions? If i cant make this work, i will just make it so it works slightly differently when
    viewev in firefox so that it can just open in one place. All ideas appreciated. ....
  3. Login Script For Vbulletin.
    (11)
    For some reason when I try to logon from the main page it doesnt work, it just brings me to the
    forums unlogged. Anyone here have any ideas whats wrong with my coding? Heres the webpage:
    www.ageofilluminati.com Heres the coding im Using: QUOTE
    Forgot password? Register for free! ....
  4. Download Script
    (10)
    hey all, on my website, i would to link to files that i have created/found. since these files are
    larger than 5mb, and i didn't want to waste my precious 500mb space, i hosted them on fileden,
    an online file storage site allowing hotlinking. an example of a url from this site is:
    http://www.fileden.com/files/2007/10/20/15...some%20file.mp3 so anyway, on one of my pages i would
    like to have a link to one of these files. however, instead of streaming the file as the website
    would normally do for the mp3 extension, i would like to 'force' the save link as /....
  5. Streaming Video Capture On Linux
    this script will download all the stream video using linux mplayer (2)
    i was looking for video capter on linux and i coldent find one so i rote one of my one if you use
    linux then you can try this script and if you need any hep just ask CODE #!/bin/bash #      
    # mplayer auto dump stream script #this script will download all the stream files in the ./zam_list
    files #this script by (mohammed tawfeek) zamaliphe@gmail.com #i have do this to be able to watch
    the video on Linux #if you think it is illegally or some thing just  don't tel me that ha #©
    #bash 6/6/2006 download_folder="./video/" #grep -e HREF ./asx/*.asx > ./list1.tx....
  6. Php - Ajax: E-mail Protection, Clickable Image
    (2)
    Description Concept sparked by the following topic: Email Address Protection From Spam Bots
    . The idea is to have an image, when clicked on, turn into selectable text. The e-mail is encoded,
    and that encoding is sent to the server through AJAX to be decoded via PHP. After it is decoded, it
    gets sent back to be inserted into a text field which is automatically selected upon clicking the
    image. I have decided to keep things limited to one page for now, where the concept can be easily
    seen. Code CODE $get = $_GET ; if ($get != ""){ echo "mailto: ".bas....
  7. Lightbox Script Variations
    (0)
    When the Web 2.0 and Ajax era kicked the best of the best in programmers started creating scripts of
    various kinds. One of these scripts called Lightbox has one of the biggest impact I have notice, it
    is well customizable to fit various formats, such as images, videos, and even maps. To start off I
    will post a link to the original source of the script, I think. Lightbox The object of this
    script is simple, when a user clicks on a thumbnail version of an image it does smooth transition of
    a pop up image that is larger, usually the original size, and when the user cl....
  8. Ajax - A New Technology
    AJAX relies on Java Script (10)
    Recently i did one of my project using AJAX and i could experience the real advantage of this
    Language , What do you say about that ?....
  9. Looking For Phpbb Script
    (2)
    Hi Friends, I am new to this phpbb script, I come across some features in some site... In some
    sites, the user should reply to the post to view the hidden content. ... Where can I find this kind
    of scripts or plug-ins... Please reply me in this thread.......
  10. I Am Looking For Ideas For A Mirc Addon
    I want your ideas (2)
    Well im currently between 2 projects that im scripting and im bored with them haha!! Just looking
    for ideas for something else i can make... Maybe just sumthing little that u want made, i will make
    it for you and release it here. I have a fairly wide range of scripting knowledge and i will try to
    make most things... Always looking to learn more things also Ta....
  11. Ruby On Rails, Ajax, Scriptaculous, Etc.
    (1)
    Since Web 2.0 has become one of the top buzzwords nowadays, I'm curious about the new languages:
    Ruby (on Rails), AJAX and scriptaculous are several methods programmers use to make web
    applications. I'd like to build some applications, but the trouble is where to start. How easy
    is it to make a web app in the first place? Which programs/languages have a learning curve
    that's not so steep? ....
  12. Swf Cd Help Needed Please
    Need assistance with a next/previous page script (1)
    Question is: I have a web page that displays a flash file that zooms and pans, but the next page
    button doesnt work. 1. Can the next page work and load the next or previous numbered file? 2. Does
    it have to have all pages in one file, then it calls the next frame? I can e-mail you the 3
    pages/files directly, firewall wont let me pload them. Thank you....
  13. How To Auto Stretch An Iframe?
    (6)
    Hello, I have this website I'm working on which has an iframe were all the links in my menus
    etc go to. All of that content I'v put in a table. The iframe itself (on my index page) is in a
    table to. But not every page I linked in the iframe is the same height. So would like to know if
    there is a solution that works to actually let the iframe automatically be resized to the page that
    loads in it. I just want the iframe on my index.html page to stretch automatically, so that I dont
    have to change the widths and all that stuff if I updated my pages, that load in t....
  14. How Do I Script A Tutorial Submit Site
    (3)
    I am very interested in learning how to create or start my own tutorial submitt site. What do I
    need to learn ? What do I need to have. Is there a script that can be made up or a software? What
    I would like to do is start my own tutorial submit site. something similar to good-tutorials and or
    pixel2life except those sites are really big and cover many tutoriasl for many different programs.
    Id like to just cover tutorials for maybe a total of 3 to 4 different programs. Im sure I need
    hosting a domain a site and some good forums to get something good going. But t....
  15. Error In Purchased Script
    Help Me? (9)
    Ok well i bought a script off the net and tried uploading it to my server and it gave me this error
    Fatal error: Unable to read 22293 bytes in /home/ancient/public_html/index.php on line 0 so i
    contacted the guy who made the script and he said there was nothing wrong with the script and gave
    me a ftp to his account and told me to upload the it there and it works on there so i tried another
    script from another guy and i get same error you guys know anything about it???? Moving from
    Computinghost > Technical Support to Programming. Edited topic title--"Help with a scr....
  16. Need Script Please
    need script (4)
    Hey everyone i need a script for a password protected page but not just that i also want and
    registration form with it can n e help....
  17. What Is A News Script?
    Fusion News? Cute News? (1)
    What do news scripts such as Fusion News and Cute News do? Does it provide local news or global
    news or something? Or is it something else?....

    1. Looking for make, auto, updating, shoutbox, type, script, ideas, involving, ajax, im,

Searching Video's for make, auto, updating, shoutbox, type, script, ideas, involving, ajax, im,
See Also,
advertisement


How Can I Make An Auto-updating Shoutbox Type Script? - I have a few ideas involving AJAX but im looking for something more..

Affordable Web Hosting, Low cost Web Hosting - ComputingHost.com