Link to home
Start Free TrialLog in
Avatar of Trexgreen
Trexgreen

asked on

ColdFusion and AJAX to read query

I have a query that check if a user in my forum has a private message or not, I would like to create an AJAX for this query that it will be checking for new private messages every 5 minutes or so, and update the inbox variable.

Right now this query executes everytime the user logs in, and it will update the header menu for the inbox.

example inbox menu:

INBOX ----> no message
INBOX (1) ---> 1 message

since this menu is in the header the query is executed everytime the page is reloaded or the user goes to another page, but I would like to add an AJAX code so that the menu is updaded without having to refresh the page.

I've been looking around and I cannot find any information on how to load a query every so often.

Thank you...
Avatar of erikTsomik
erikTsomik
Flag of United States of America image

can you just refresh the page every 5 sec .
Something like this

<meta http-equiv="refresh" content="5; URL=http://www.someurl.com">

This will automatically refresh for every 5 seconds.

You can use <cfschedule>.  Perhaps once the user logs in, create a new cfschedule that runs every 5 minutes.  When the user logs out (and/or in your application.cfc's onSessionEnd() function) kill the cfschedule.
Sorry, my answer's not probably on the right tracks, as I guess you're looking for an Ajax solution.  Look into Javascript timers instead.
Avatar of Trexgreen
Trexgreen

ASKER

I can, but that would be the same as what I have now... everytime you change a page it would reload the query.

Why is it not a good idea to use AJAX for that?
ASKER CERTIFIED SOLUTION
Avatar of azadisaryev
azadisaryev
Flag of Hong Kong image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
IMPORTANT UPDATE!
for anyone trying to use the solution: i have typo in my code!
the correct tag is, of course, <CFcomponent>, not <component>. make sure you correct this if you are using the code!

Azadi