title: Ajax success function trigger data
body: <p>i have problem with my code. Lets say i have PHP site in background and this site do something. Lets say in this site i have <code>$status = "1";</code> and in my ajax code i have:</p>
  
  <pre><code>$.ajax({
      url: 'src/single.php',
      type: 'POST',
      data: {single:1, id:id},
      success: function(data){
          $('#live_data').val('');
          $('#live_data').html(data);
      }
  });
  </code></pre>
  
  <p>and i want to know if it si possible to trigger $status from my php page. Something like </p>
  
  <pre><code>success: function(data){
     if (data.status == '1') {
          $('#live_data').val('');
          $('#live_data').html(data);
     } if (data.status == '2') {
          $('#search_result').val('');
          $('#search_result').html(data);
     }
  </code></pre>
  
  <p>Thank you for help if you can :)</p>
  
  <p>EDIT:</p>
  
  <p>So here is my code:</p>
  
  <p>first is for fetch data from db,
  and second is for search data from db,
  And third is for fetch single data from db.
  It work good but problem is that when i click on row it display results 2times first from show and second from search
  But in search it is correct.</p>
  
  <p>This <code>$('#live_data')</code> is for show.php data and <code>$('#search_result')</code> is for search data. And when i click on row from show.php it will display result 2times. First from show.php and second from search.php but when i click on row from search.php it display correctly (only one result). I know it is cuz i have </p>
  
  <pre><code>$('#live_data').val('');
  $('#live_data').html(data);
  </code></pre>
  
  <p>but when i want to hide duplicated result from show.php i do <code>$('#search_result').val('');</code> but then i hide my single data from search.php</p>
  
  <p>This is why i want to controll it with if statement</p>
  
  <p>I attach images below</p>
  
  <p>ajax for single data fetch:</p>
  
  <pre><code>//jeden zaznam
      $(document).on('click', '.clickable-row', function(){
  
          var id = $(this).data("id2");
  
          $.ajax({
              url: 'src/single.php',
              type: 'POST',
              data: {single:1, id:id},
              success: function(data){
                  $('#live_data').val('');
                  $('#live_data').html(data);
                  $('#search_result').html(data);
              }
          });
      });
  </code></pre>
  
  <p>First: </p>
  
  <pre><code>&lt;?php 
  
      include("db.php");
  
      $output = "";
      $sql = "SELECT * FROM otk";
  
      $result = mysqli_query($conn, $sql);
  
      $output .= "&lt;table class='table table-hover'&gt;
                      &lt;thead&gt;
                          &lt;tr&gt;
                              &lt;th&gt;Číslo zákazky&lt;/th&gt;
                              &lt;th&gt;Pozícia&lt;/th&gt;
                              &lt;th&gt;Stav&lt;/th&gt;
                              &lt;th&gt;Dátum&lt;/th&gt;
                              &lt;th&gt;Operátor&lt;/th&gt;
                          &lt;/tr&gt;
                      &lt;/thead&gt;";
      while ($row = mysqli_fetch_array($result))
      {
          $output .= "&lt;tr class = 'clickable-row' data-id2 ='".$row['id_otk']."'&gt;
                          &lt;td&gt;".$row['kod_otk']."&lt;/td&gt;
                          &lt;td&gt;".$row['poz_otk']."&lt;/td&gt;
                          &lt;td&gt;".$row['stav_otk']."&lt;/td&gt;
                          &lt;td&gt;".$row['datum_otk']."&lt;/td&gt;
                          &lt;td&gt;".$row['op_otk']."&lt;/td&gt;
                      &lt;/tr&gt;";
      }
  
      $output .= "&lt;/table&gt;";
  
      echo $output;
  
  ?&gt;
  </code></pre>
  
  <p>Second:</p>
  
  <pre><code>&lt;?php 
  
  if (isset($_POST['search']))
  {
      include("db.php");
  
      $search_text = mysqli_real_escape_string($conn, $_POST['search_text']);
      $search = htmlspecialchars($search_text);
  
      $output = "";
      $output .= "
          &lt;table class='table table-hover'&gt;
                      &lt;thead&gt;
                          &lt;tr&gt;
                              &lt;th&gt;Číslo zákazky&lt;/th&gt;
                              &lt;th&gt;Pozícia&lt;/th&gt;
                              &lt;th&gt;Stav&lt;/th&gt;
                              &lt;th&gt;Dátum&lt;/th&gt;
                              &lt;th&gt;Operátor&lt;/th&gt;
                          &lt;/tr&gt;
                      &lt;/thead&gt;";
  
      $sql = "SELECT * FROM otk WHERE kod_otk LIKE '%".$search."%'";
      $result = mysqli_query($conn, $sql);
  
      if (mysqli_num_rows($result) &gt; 0)
      {
          while($row = mysqli_fetch_array($result))
          {
              $output .= "
                  &lt;tr class = 'clickable-row' data-id2 ='".$row['id_otk']."'&gt;
                      &lt;td&gt;".$row['kod_otk']."&lt;/td&gt;
                      &lt;td&gt;".$row['poz_otk']."&lt;/td&gt;
                      &lt;td&gt;".$row['stav_otk']."&lt;/td&gt;
                      &lt;td&gt;".$row['datum_otk']."&lt;/td&gt;
                      &lt;td&gt;".$row['op_otk']."&lt;/td&gt;
                  &lt;/tr&gt;";
          }
  
          $output .= "&lt;/table&gt;
                          &lt;div class='d-flex justify-content-center'&gt;
                          &lt;button class='btn btn-primary' onclick='history.go();'&gt;Späť&lt;/button&gt;
                      &lt;/div&gt;";
  
          echo $output;
  
      } else {
          echo "Žiadny záznam";
      }
  }
  
  
  ?&gt;
  </code></pre>
  
  <p>Third: </p>
  
  <pre><code>&lt;?php
  
  if (isset($_POST['single']))
  {
      include("db.php");
  
      $id = mysqli_real_escape_string($conn, $_POST['id']);
      echo "id je: ".$id;
  
      $sql = "SELECT * FROM otk WHERE id_otk = '".$id."'";
      $result = mysqli_query($conn, $sql);
  
      $output = "&lt;table class='table table-hovrt'&gt;
                      &lt;thead&gt;
                          &lt;tr&gt;
                              &lt;th&gt;Číslo zákazky&lt;/th&gt;
                              &lt;th&gt;Pozícia&lt;/th&gt;
                              &lt;th&gt;Stav&lt;/th&gt;
                              &lt;th&gt;Poradové číslo&lt;/th&gt;
                              &lt;th&gt;Technológia&lt;/th&gt;
                              &lt;th&gt;Dokument&lt;/th&gt;
                              &lt;th&gt;Zariadenie&lt;/th&gt;
                              &lt;th&gt;Operátor&lt;/th&gt;
                              &lt;th&gt;Dátum&lt;/th&gt;
                          &lt;/tr&gt;
                      &lt;/thead&gt;";
  
      if (mysqli_num_rows($result) &gt; 0)
      {
          while ($row = mysqli_fetch_array($result))
          {
              $output .= "
                  &lt;tr&gt;
                      &lt;td&gt;".$row['kod_otk']."&lt;/td&gt;
                      &lt;td&gt;".$row['poz_otk']."&lt;/td&gt;
                      &lt;td&gt;".$row['stav_otk']."&lt;/td&gt;
                      &lt;td&gt;".$row['cislo_otk']."&lt;/td&gt;
                      &lt;td&gt;".$row['tech_otk']."&lt;/td&gt;
                      &lt;td&gt;".$row['dok_otk']."&lt;/td&gt;
                      &lt;td&gt;".$row['zar_otk']."&lt;/td&gt;
                      &lt;td&gt;".$row['op_otk']."&lt;/td&gt;
                      &lt;td&gt;".$row['datum_otk']."&lt;/td&gt;
                  &lt;/tr&gt;";
          }
  
          $output .= "&lt;/table&gt;
                      &lt;div class='d-flex justify-content-center'&gt;
                          &lt;button class='btn btn-primary' onclick='history.go(-2);'&gt;Späť&lt;/button&gt;
                      &lt;/div&gt;";
  
          echo $output;
      } else {
          echo "Error: " .  mysqli_error($sql);
      }
  }
  
  
  
  ?&gt;
  </code></pre>
  
  <p>Image01:</p>
  
  <p><a href="https://i.stack.imgur.com/5fAGm.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5fAGm.jpg" alt="enter image description here"></a></p>
  
  <p>Image02:
  <a href="https://i.stack.imgur.com/hei9j.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/hei9j.jpg" alt="enter image description here"></a></p>