2016-09-21 17 views
-1

javascriptでさらにステートメントを実行する前にbootbox.prompt()の結果を待つ方法はありますか?私は、コードを次している

var bootboxresult; 

bootbox.prompt('Please enter some data', function(result) { 
if (result != null) { 
bootboxresult = result; 
}}); 

alert(bootboxresult); 

if(bootboxresult === null) 
{ 
return; 
} 

if(bootboxresult != null) 
{ 
Some Code To Excecute 
} 

コードは、プロンプトボックスが表示されますが、常に「bootboxresult」変数の内容は、nullまたは未定義です。

さらに、bootbox.prompt()が "bootboxresult"変数に値を格納するのを待つ必要があります。

お知らせください。

+0

可能な重複http://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an -asynchronous-call) – CBroe

+0

ありがとう@CBroe、それは私の同期と非同期呼び出しの概念を助け、クリアしました。 –

答えて

1

あなたはブートボックスのコールバックの中にすべてのコードを書くことができると思います。以下の例を参照してください。

 var popup_content = "<b>Are you sure?</b><br><br>Do you want to delete?"; 
     bootbox.confirm(popup_content, function(result) { 
       if(result){ 
        // Write all your code here. 

       }else{ 
       // else part code goes here 
       } 

     }); 
[私は非同期呼び出しからの応答を返すにはどうしますか?](の
関連する問題