Link to home
Start Free TrialLog in
Avatar of j-tanner
j-tanner

asked on

Coldfusion Ajax timer probelms

So i needed to be able to check an inbox, and found this post:
https://www.experts-exchange.com/questions/24346330/ColdFusion-and-AJAX-to-read-query.html?sfQueryTermInfo=1+10+8+ajax+coldfus+timer

My problem is that in firefox nothing happens & IE throws an error - ive since found out, im getting "Error thrown and not caught" at line 798 within cfajax.js

Current result can be seen at http://www.brandirectorv2.com/test.cfm
<!--- test.cfm --->
<cfajaxproxy cfc="includes.inbox" jsclassname="inboxProxy">
<head>
<script type="text/javascript">
var p = new inboxProxy();
var checkInbox = function(userid){
 p.setCallbackHandler(updateInbox);
 p.setErrorHandler(pErr);
 p.checkUserInbox(userid);
};
var updateInbox = function(result){
 document.getElementById("messagecount").innerHTML = " ("+result+")";
};
var pErr = function(code, message){
 alert("Error! Could not check your inbox...\nError Code: "+code+"\nError Message: "+message);
};
var initInboxCheck = function(userid){
 checkInbox(userid);
 setInterval(checkInbox(userid), 5000);
};
</script>
</head>
<cfset user_id="1">
<body onload="initInboxCheck(<cfoutput>#user_id#</cfoutput>);">
<div id="header"><a href="viewinbox.cfm">INBOX<span id="messagecount"></span></a></div>
</body>
</html>
 
<!--- includes/inbox.cfc --->
<component displayname="inbox" output="no">
<cffunction name="checkUserInbox" access="remote" returntype="numeric" output="no">
 <cfargument name="userID" type="numeric" required="yes">
 <cfset var queryInbox = "">
 <cfquery name="queryInbox" datasource="#request.dsn#" username="#request.uid#" password="#request.pwd#">
 SELECT * FROM tbl_messages WHERE msg_to = <cfqueryparam cfsqltype="cf_sql_integer" value="#arguments.userID#">
 </cfquery>
 <cfreturn queryInbox.recordcount />
</cffunction>
</component>

Open in new window

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
SOLUTION
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
SOLUTION
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
Avatar of j-tanner
j-tanner

ASKER

Hi,

Thankyou for the reply, that has stopped the cfajax error :), however the script is still failing...
Firebug shows:

useless setInterval call (missing quotes around argument?)
                                   setInterval(checkInbox(userid), 5000);

I researched setInterval & many say that whilst you can call a function, you cant pass a variable? if i put speech marks around it, it still stops & firebug says "userid is not defined"

Any thoughts?
Actually, i solved it :D... you may want to update code in he other post as well...

i replaced:

setInterval(checkInbox(userid), 5000);

with:

setInterval(function(){checkInbox(userid)}, 5000);
Thankyou for your help