Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can make your AJAX request synchronous. <a href="https://developer.mozilla.org/en-US/docs/DOM/XMLHttpRequest/Synchronous_and_Asynchronous_Requests" rel="nofollow">https://developer.mozilla.org/en-US/docs/DOM/XMLHttpRequest/Synchronous_and_Asynchronous_Requests</a></p> <pre><code>var request = new XMLHttpRequest(); // Last parameter makes it not asnychronous request.open('GET', 'http://www.mozilla.org/', false); request.send(null); // Won't get here until the network call finishes if (request.status === 200) { console.log(request.responseText); } </code></pre> <p>However, that will block the UI while waiting for the server to respond, which is almost never what you want. In that case, you should use a callback to process results.</p> <p>Here's an example using a callback without relying on a global variable. You should always run away from those</p> <pre><code>function ShowInserisciCommerciale( ) { getElementiEsistenti(function(responseText) { JSON.parse(responseText); }); } function getElementiEsistenti(successCallback){ var url = "http://127.0.0.1:8080/Tesi/Ingredienti"; var xmlHttp = new XMLHttpRequest(); xmlHttp.open("POST", url, false); xmlHttp.send(null); xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); xmlHttp.onreadystatechange = function() { if (xmlHttp.readyState == 4) // COMPLETED { if (xmlHttp.status == 200) // SUCCESSFUL { successCallback(xmlHttp.responseText); } else { alert("An error occurred while communicating with login server."); } } }; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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