Note that there are some explanatory texts on larger screens.

plurals
  1. POJavascript Asynchronous to Synchronous task
    text
    copied!<p>I have the following code (these codes are in separated js files ) :</p> <p>Code 1 (home.js):</p> <pre><code>alert('1'); BeginGetDashboardsMethod(); alert('5'); </code></pre> <p>Code 2(script.js) :</p> <pre><code>function BeginGetDashboardsMethod(){ var stop = 'false'; alert('2'); try { Service.GetDashboardsMobile("" + curr_cod_user, SuccessGetDashboardMethod, ErrorGetDashboardMethod); } catch (e) { } function SuccessGetDashboardMethod(result) { alert('3'); json = result; json = JSON.parse(json); ListDashboards(json); } function ErrorGetDashboardMethod(err) { alert(JSON.stringify(err)); } function ListDashboards(json) { alert('4'); for (var i = 0; i &lt; json.Dashboards.length; i++) { if (json.Dashboards.length === 1) Items = "[{key:\'" + json.Dashboards[i].OBV_ST_TITULO + "\', title:\'" + json.Dashboards[i].OBV_ST_TITULO + "\'}]"; else { if (i == 0) { Items += "[{key:\'" + json.Dashboards[i].OBV_ST_TITULO + "\', title:\'" + json.Dashboards[i].OBV_ST_TITULO + "\'} "; } else if (i + 1 == json.Dashboards.length) { Items += ",{key:\'" + json.Dashboards[i].OBV_ST_TITULO + "\', title:\'" + json.Dashboards[i].OBV_ST_TITULO + "\'}] "; } else { Items += ",{key:\'" + json.Dashboards[i].OBV_ST_TITULO + "\', title:\'" + json.Dashboards[i].OBV_ST_TITULO + "\'} "; } } } obj = eval(Items); } } </code></pre> <p>My code works asynchronous. After Service.GetDashboardsMobile call the code "skip" Success callback and execute alert(5); while executing callback. Is there a way to make that functions synchronous?</p> <p>To be more exactly, I want that sequence : alert('1');-->alert('2');-->alert('3');-->alert('4');-->alert('5')</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload