I 've made a thorough search, however I cannot find something clear about my assumption. I 've used the following code:
<?php
session_start();
if (isset($_SESSION['valid_user']) && $_SESSION['from']==1)
{
?>
<script type="text/javascript">
$.ajax({
method:"POST",
dataType: 'json',
url:"user.php",
success: function(newdata) {
if (newdata == "nothing")
{
var temp1 ="no data!";
$("#results_ribbon").text(temp1);
return;
}
var temp1 ="You have: ".concat(newdata);
$("#results_ribbon").text(temp1);
}
});
</script>
which is part of a php file. The HTML code which builds the DOM follows after the above code...
So, I'd expect div with id="results_ribbon" not to have the right content since #results_ribbon does not exist, yet. However, everything works fine. This led me to assume that $.ajax call waits to be executed after DOM loading. Am I right? If not why the above happens?