0

I am making an asynchronous call using plain java script whose result is to be used further. Here are the statements.

var x = function call(); //Asynchronous call
 alert(x);

here I am getting x as "undefined" .

then I tried to check the status of x using While loop as below

while(1){
 if(x != "undefined"){
 alert(x);
 break;
 }
}

Then the while condition is never getting a break. It goes on execution. Help me out to hoe to stop the execution until i receive result from Asynchronous call?

asked Nov 26, 2013 at 12:40
1
  • 2
    The value of x will never change once your function call has returned. Instead, you will likely be able to pass a callback function somewhere in your asynchronous call, and this function will be called when the async request is complete. We can't really help you until you post the code for the asynchronous function... Commented Nov 26, 2013 at 12:42

1 Answer 1

3

Asynchronous call returns the output once it processed. So your function should accept a callback which indeed runs when the function is executed.

SO your code should look like this

function asynccall (args..., callback);
function callback(data){
alert(data); //Get the response and use it furher
}
answered Nov 26, 2013 at 12:53
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.