/    Sign up×
Community /Pin to ProfileBookmark

Working with alert/Not working without alert

Hi @ll!

I have a stupid problem on hands…here’s what happens:

I have this sequence of instructions:
–code
case “A”
function1();
function2();
alert(“test”);
break;
–code

The function function2() uses XMLHTTP to return some results and the async propertie is set to “false”…so everything’s fine…

When I run the code like above it works fine, but when I remove the alert(“test”) statement seams like code’s running throw without having function2() results…

Is there anyway to pause execution for some milisecs?? Is there especial propertie in the alert that makes this work?

Thx in advance for help.

Chears,
Pedro

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@javaNoobieNov 04.2004 — use setTimeout. However, it doesnt pause the code execution. Lines after setTimeout will start to be executed without waiting for the timeout to finish.
<i>
</i>function a(){
alert('a');
}

function b(){
alert('b');
}

function c(){
alert('c');
}
a(); //call function a
setTimeout('b()',1000); //set function b to run in 1sec
c(); //this function will run before b() is executed
Copy linkTweet thisAlerts:
@pgnbnauthorNov 04.2004 — Thx for the tip m8, but I've already tried that and doesn't work...

Chears,

Pedro
Copy linkTweet thisAlerts:
@JSchwarzFeb 14.2005 — Pedro, did you ever find a solution? What was it?

Thanks,

-Jeff
Copy linkTweet thisAlerts:
@Warren86Feb 14.2005 — I see that this sequence is within a case statement. I haven't tested the following, it's just a suggestion.

function1(isBoth){

..... all the other code in this function

if (isBoth){function2()}

}


--code

case "A"

function1(true);

break;

--code
Copy linkTweet thisAlerts:
@UltimaterFeb 15.2005 — May I point out in general that the alert function

always returns false.

So if your code works with alert, and doesn't without,

try replacing the function [b]alert()[/b] with:

[b]false[/b] or [b]someFunctionThatReturnsFalse()[/b]
×

Success!

Help @pgnbn 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 6.17,
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: @nearjob,
tipped: article
amount: 1000 SATS,

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

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...