/    Sign up×
Community /Pin to ProfileBookmark

Help with setTimeout

I am trying to run a simple recursive function call using setTimeout() but with little success, can someone help me out.

This is my code fragment,

[CODE]function ajaxQ(param){
if(accessKey){
accessKey = false;
ajaxRequest(“dj-content/maps/layerResults.php” + param, loadLayerHandle);
}else{
alert(param);
timer = setTimeout(‘ajaxQ(param)’,1000);
}
}[/CODE]

The variable param is not getting passed to the function after setTimeout(‘ajaxQ(param)’,1000), someone also suggested I try this but nothing happens.

[CODE] function ajaxQ(param){
if(accessKey){
accessKey = false;
ajaxRequest(“dj-content/maps/layerResults.php” + param, loadLayerHandle);
}else{
alert(param);
timer = setTimeout(‘function () {ajaxQ(param);}’,1000);
}
}[/CODE]

Thanks in advance,
Levi

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@magentaplacentaJan 16.2008 — Have you tried the timeout function as a non-string?

timer = setTimeout(ajaxQ(param),1000);

timer = setTimeout(function () {ajaxQ(param);},1000);
Copy linkTweet thisAlerts:
@puttyauthorJan 16.2008 — yes and the function is passed but without delaying for any time, it just loops very quickly until a stack overload error happens.
Copy linkTweet thisAlerts:
@puttyauthorJan 16.2008 — Success, got it working with this...

…

strCode = "ajaxQ('" + param + "')";

timer = setTimeout(strCode,1000);

…

What a stupid bug to have, 30 min of my life wasted.
×

Success!

Help @putty 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.23,
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,
)...