title: How to get an value from a php page with js
body: <p>I am trying to capture a value that is calculated on a PHP page called "classes_day.php" at the same time as I pass a value per GET, "? Day = YYYY-mm-dd" to it. How do I do this with JS or JQuery?</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;?php
    
    // aulas_dia.php
  
   include '../config.php';
  
   $exped_duration = 14*60;
  
   if (isset($_GET['data'])) {
    $data = $_GET['data'];
  
    $query = "SELECT * FROM `task` WHERE `dia` LIKE ".$data."";
    $result = mysqli_query($link,$query);
    $soma = 0;
    while ($row = mysqli_fetch_assoc($result)) {
     $soma = $soma+$row['duration'];
    }
  
    $aulas_free = floor(($exped_duration-$soma)/50);
    echo $aulas_free;
   }
  
  ?&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>I already tried using an iframe and contentwindow, but iframe gets the value and the contentwindow is empty (weird isn't it?).</p>
  
  <hr>
  
  <p>Following Barmar's tip, I'm using $ .get, but I don't know why this loop is not working, can anyone help me?</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>for (i = 0; i &lt; num_days; i++) {
    x = (first_day+i)%7;
    y = (first_day+i-x)/7;
    h_dia(String(y)+String(x),i+1);
    data_c = ano+"-"+mes+"-"+String(i+1);
    $.get("aulas_dia.php?data="+data_c, function(data){ 
      console.log(String(y)+String(x)+" - "+data_c+" - "+data); 
      set_aulas_fun(String(y)+String(x),data);
    });
  }</code></pre>
  </div>
  </div>
  </p>