title: Javascript ajax (get)
body: <p>I'm trying to do a simple table and the data is populated by php/mysql on wordpress.</p>
  
  <p>My objective is: when the user click on a <code>&lt;th&gt;</code>, the ajax will reload the table with a <code>get</code> parameter, so the table will be ordered by the specific column.</p>
  
  <p>If I access my URL like this: <code>localhost/table?data=desc or localhost/table?data=asc</code> it works, but I want to do that with ajax. Here's part of my code:</p>
  
  <p>JS:</p>
  
  <pre><code>    $(document).on('click','#order_data',function() {
          $.ajax({
              url: '/table?data=desc',
              type: 'GET',
              success: function(msg) {
                  $("#main_container").load(location.href + " #table_demos");
              }
          });
      });
  });
  </code></pre>
  
  <p>HTML</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;div id="main_container"&gt;
  &lt;table class="table table-striped table-bordered table-hover" id="table_demos"&gt;
   &lt;thead&gt;
    &lt;th id="order_data"&gt;Data
    &lt;?php
    if(isset($_GET['data']) &amp;&amp; $_GET['data'] == 'asc') {
     echo '&lt;i class="fa fa-arrow-up" aria-hidden="true"&gt;&lt;/i&gt;';
    } else if(isset($_GET['data']) &amp;&amp; $_GET['data'] == 'desc') {
     echo '&lt;i class="fa fa-arrow-down" aria-hidden="true"&gt;&lt;/i&gt;';
    }
    ?&gt;
    &lt;/th&gt;
    &lt;th&gt;Versus&lt;/th&gt;
    &lt;th&gt;Mapa&lt;/th&gt;
    &lt;th&gt;Placar&lt;/th&gt;
    &lt;th&gt;Baixar&lt;/th&gt;
   &lt;/thead&gt;
   &lt;tbody&gt;
  &lt;?php
   $conexao = mysqli_connect("localhost","root","321","local_test");
  
   if(mysqli_connect_errno()) {
      echo "Falha na conexão MySQL.";
     } else {
    $data = '';
    if(isset($_GET['data'])) {
     if($_GET['data'] == 'asc') {
      $data = 'order by data asc';
     } else if($_GET['data'] == 'desc') {
      $data = 'order by data desc';
     } 
    }
    $query = mysqli_query($conexao,"SELECT * FROM demo_cadastro {$data}");
    while ($row = mysqli_fetch_assoc($query)) {
     echo '&lt;tr&gt;';
     echo '&lt;td&gt;' . transformar_data($row['data']) . '&lt;/td&gt;';
     echo '&lt;td&gt;&lt;a href="' . $row['link_adversario'] . '" target="_blank"&gt;' . $row['nome_adversario'] . '&lt;/a&gt;&lt;/td&gt;';
     echo '&lt;td&gt;' . $row['mapa'] . '&lt;/td&gt;';
     echo '&lt;td&gt;' . $row['pontos_marcados'] . 'x' . $row['pontos_sofridos'] . '&lt;/td&gt;';
     if($row['link_demo'] == '#') {
      echo '&lt;td&gt;&lt;a href="' . $row['link_demo'] . '" class="demo-indisponivel-swal"&gt;&lt;i class="fa fa-cloud-download" aria-hidden="true"&gt;&lt;/i&gt;&lt;/a&gt;&lt;/td&gt;';
     } else {
      echo '&lt;td&gt;&lt;a href="' . $row['link_demo'] . '"&gt;&lt;i class="fa fa-cloud-download" aria-hidden="true"&gt;&lt;/i&gt;&lt;/a&gt;&lt;/td&gt;';
     }
     echo '&lt;/tr&gt;';
    }
  
    mysqli_free_result($query);
   }
  
   mysqli_close($conexao);
    
   function transformar_data($data) {
    $data_explode = explode('-', $data);
    return $data_explode[2] . '/' . $data_explode[1] . '/' . $data_explode[0];
   }
  ?&gt;
   &lt;/tbody&gt;
  &lt;/table&gt;
  &lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>I think i'm messing up just the ajax call...</p>
  
  <p>Thanks in advice!</p>