/    Sign up×
Community /Pin to ProfileBookmark

Hey,

I asked a question yesterday on how to make a radio updater. People responded with telling me to use Ajax. I’ve seen it in use, and figured they were right and should try it out. I’ve ran into a few questions though that I’m hoping someone can help me with.

I’ve learned that Ajax largely uses the XMLHttpRequest function. My main question though, is how to use this to check what a current php variable is. I want a way for Ajax to check a current php variable, and if its changed from 0 to 1 or 1 to 0, I want the page to be updated to display a different html code.

Another question which kinda links in with the above, is how to have the ajax distinguish whether the current php variable is different than its last check. I really am lost when it comes to Ajax.

An Ajax script that kinda does this:

Radio Online —Ajax Check, Variable Changed–> Refresh to backup music —Ajax Check, No Variable Change–> Page doesn’t refresh —Ajax Check, Variable Change–> Refresh to Radio

Thats pretty much what I’m trying to do, and I just have no idea what I need to use, besides the XMLHttpRequest function.

Any insight on this would be great!

Thanks in advance for any help.

to post a comment
JavaScript

10 Comments(s)

Copy linkTweet thisAlerts:
@lamdkFeb 20.2008 — Ajax.Updater????

http://www.prototypejs.org/api/ajax/updater

[SIZE="7"]=D[/SIZE]
Copy linkTweet thisAlerts:
@PhantomBurnauthorFeb 20.2008 — Ajax.Updater????

http://www.prototypejs.org/api/ajax/updater

[SIZE="7"]=D[/SIZE][/QUOTE]


Can this be used with php variables? I looked at the page, and it seems similar to what I want. Just not sure if its quite it. I'm going to continue to read up on the site you gave me, then try to use the godly google to dig up some examples of it being used.

If this works, thanks! =D
Copy linkTweet thisAlerts:
@PhantomBurnauthorFeb 20.2008 — Hmmmm....

I kept reading further into the site you gave me...I'm starting to feel its not what I'm looking for.

The link you gave me is for, what it looks like, a Ajax framework thing. It says I need to download it for it to work. So I click download and it just brings me to a long js file. Does that mean, that in order to get that function to work, I need to link to that .js in my file's header?

Also not sure if this is what I want, because from what I can tell, its a custom made function sorta thing. I tried googling it and because its custom, it doesn't have a lot of examples of it being used XD

I'll continue looking into it, and if it seems to be the only way to get what I want working, I guess I'll use it =D

EDIT: Ha, I'm knew here, and I have a VERY small side question; and idea on why it takes so long for a post to be made? I made a post before this one, and it has yet to appear...Just something I'm kinda curious about =D
Copy linkTweet thisAlerts:
@yamaharussFeb 20.2008 — What language are you using on the server? You could use session variables or cookies to compare variable changes.
Copy linkTweet thisAlerts:
@PhantomBurnauthorFeb 20.2008 — Right now the variables are in php. Right now I'm using

if($streamstatus == "1"){

echo'

blahblahblah html goes here';

}

if($streamstatus == "0")

{

echo'

blahblahblah other html goes here';

}

to display the radio's current stats (current dj, current song, number of listeners). 1 is online, 0 is offline (When its 0, it displays a message saying we are offline).

Not sure if you needed that last example of code I use, just thought I'd through that in =D
Copy linkTweet thisAlerts:
@yamaharussFeb 20.2008 — Why not write the same current value to a session variable, then compare the chosen value to the session value.
Copy linkTweet thisAlerts:
@PhantomBurnauthorFeb 21.2008 — I've never really done anything with sessions in the past, and Ajax seemed to be the direction people were pointing me in.

So...With a session, would a session be able to check that php variable every 60secs? And with a session, would it be one session that does that, or two different session things, or what...? Yea, I feel like Ajax is the nicest way to go =P
Copy linkTweet thisAlerts:
@yamaharussFeb 21.2008 — How exactly are variables changed?
Copy linkTweet thisAlerts:
@lamdkFeb 21.2008 — Can this be used with php variables? I looked at the page, and it seems similar to what I want. Just not sure if its quite it. I'm going to continue to read up on the site you gave me, then try to use the godly google to dig up some examples of it being used.

If this works, thanks! =D[/QUOTE]


lol i dunno anything about php but, that function was the first thing that popped into my mind when reading the thread title "Ajax Updater" so i felt irked to post mwahahah?
Copy linkTweet thisAlerts:
@PhantomBurnauthorFeb 21.2008 — How exactly are variables changed?[/QUOTE]

Do you mean in my script? Well, the current variables are changed by the current status of the radio server. I need the page to refresh though to have the variables get refreshed.
×

Success!

Help @PhantomBurn spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...