title: AJAX returns whole html - how can i return just one value?
body: <p>(edited after first messed up version)</p>
  <p>My AJAX is returning my header.php page.I just want it to return the $result value 0 or 1.
  I am using ajax to call my generateTicket.php. There i want to generateTickets, if there currently is no other ticket. If the generation was successful it should return 1, if not 0.</p>
  <p>But currenty it is returing my header.php with my response (0 or 1) at the end. How can i prevent it from returning header.php.</p>
  <p>AJAX:</p>
  <pre><code>function generateTicket() {
    $.ajax({
      url: 'generateTicket.php',
      type: 'post',
      datatype: &quot;json&quot;,
      data: {
        showid: &lt;?php echo $showid ?&gt;,
        seats: &lt;?php echo $seats_json ?&gt;
      },
      success: function(response) {
        alert(response);  
      }
    });
  }
  </code></pre>
  <p>generateTicket.php:</p>
  <pre><code>&lt;?php 
  include('includes/header.php');
  
  //Login prüfen
  if (!$loggedIn) {
      header('Location: login.php');
      die();
  }
  
  //Variablen init
  $userid = $_SESSION['userid'];
  $showid = $_POST['showid'];
  $seats = $_POST['seats'];
  $result = 1;
  
  //Für jeden Sitzplatz ein Ticket generien generieren
  foreach($seats as $seat){
      //Datenbank Ticket laden
      $query = &quot;SELECT * FROM  ticket_uebersicht WHERE Sitzplatz LIKE ? AND VorstellungID = ? LIMIT 1&quot;;
      $statement = $pdo-&gt;prepare($query);
      $statement-&gt;execute(array($seat, $showid));
      $row = $statement-&gt;fetch();
  
      //Prüfen ob Ticket exestiert. Wenn ja -&gt; Marktplatzticket -&gt; anpassen. Wenn nein -&gt; Neues Ticket generieren
      if(!$row){
          $code = guidv4();
          $query = &quot;INSERT INTO tickets (code, UserID, VorstellungID, Sitzplatz) VALUES (?,?,?,?)&quot;;
          $statement = $pdo-&gt;prepare($query);
          $statement-&gt;execute(array($code, $userid, $showid, $seat));
          continue;
      }else{
          if($row['marktplatz'] != 0){
              $code = guidv4();
              $marketplace = '0';
              $query = &quot;UPDATE tickets SET UserID = ?, code = ?, marktplatz = ? WHERE Sitzplatz = ? AND VorstellungID = ? AND NOT marktplatz = 0 LIMIT 1&quot;;
              $statement = $pdo-&gt;prepare($query);
              $statement-&gt;execute(array($userid, $code, $marketplace, $seat,  $showid));
              
              if(!($row['UserID'] == -1)){
                  $betrag = $row['preis'] - 2;
                  $query = &quot;INSERT INTO rueckerstattung (UserID, Betrag) VALUES (?,?)&quot;;
                  $statement = $pdo-&gt;prepare($query);
                  $statement-&gt;execute(array($row['UserID'], $betrag));
              }
              continue;
          }
          $result =  0; //Fehler
      }
      
  }
  
  echo json_encode($result);
  
  //Generieren der Ticket ID (FREMDCODE)
  function guidv4($data = null) {
      // Generate 16 bytes (128 bits) of random data or use the data passed into the function.
      $data = $data ?? random_bytes(16);
      assert(strlen($data) == 16);
  
      // Set version to 0100
      $data[6] = chr(ord($data[6]) &amp; 0x0f | 0x40);
      // Set bits 6-7 to 10
      $data[8] = chr(ord($data[8]) &amp; 0x3f | 0x80);
  
      // Output the 36 character UUID.
      return vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex($data), 4));
  }
  exit;
  ?&gt;
  </code></pre>
  <p>header.php:</p>
  <pre><code>&lt;?php
  include('db_connect.php');
  include('righthandler.php')
  ?&gt;
  
  
  &lt;!DOCTYPE html&gt;
    &lt;html lang=&quot;de&quot;&gt;
    &lt;head&gt;
      &lt;title&gt;DHBW Kino Website&lt;/title&gt;
      &lt;meta charset=&quot;utf-8&quot;&gt;
      &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1&quot;&gt;
      &lt;link href=&quot;css/style.css&quot; rel=&quot;stylesheet&quot;&gt;
  
      &lt;!-- Insert Favicon to make it show in Tab --&gt;
      &lt;link rel=&quot;shortcut icon&quot; type=&quot;image/x-icon&quot; href=&quot;../img/favicon.ico&quot;&gt;
  
      &lt;!-- Latest compiled and minified CSS --&gt;
      &lt;link href=&quot;https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta1/dist/css/bootstrap.min.css&quot; rel=&quot;stylesheet&quot; integrity=&quot;sha384-giJF6kkoqNQ00vy+HMDP7azOuL0xtbfIcaT9wjKHr8RbDVddVHyTfAAsrekwKmP1&quot; crossorigin=&quot;anonymous&quot;&gt;
      
      &lt;!-- jQuery library --&gt;
      &lt;script src=&quot;https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js&quot;&gt;&lt;/script&gt;
  
      &lt;!-- Popper JS --&gt;
      &lt;script src=&quot;https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js&quot;&gt;&lt;/script&gt;
      
      &lt;!-- Latest compiled JavaScript --&gt;
      &lt;script src=&quot;https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js&quot;&gt;&lt;/script&gt; 
  
      &lt;!-- Schriftart --&gt;
      &lt;script src=&quot;https://use.fontawesome.com/releases/v5.0.8/js/all.js&quot;&gt;&lt;/script&gt;
  
      &lt;!-- Bootstrap Table Pack --&gt;
      &lt;link rel=&quot;stylesheet&quot; href=&quot;https://unpkg.com/bootstrap-table@1.18.2/dist/bootstrap-table.min.css&quot;&gt;
      &lt;script src=&quot;https://unpkg.com/bootstrap-table@1.18.2/dist/bootstrap-table.min.js&quot;&gt;&lt;/script&gt;
      &lt;script src=&quot;https://cdnjs.cloudflare.com/ajax/libs/bootstrap-table/1.18.2/locale/bootstrap-table-de-DE.min.js&quot;&gt;&lt;/script&gt;
      
    &lt;/head&gt;
  
    &lt;!-- Titel/ Header der Website--&gt;
    &lt;div class=&quot;jumbotron container text-center&quot; style=&quot;margin-bottom:0&quot;&gt;
        &lt;img class=&quot;logo&quot; src=&quot;../img/logo.png&quot;  width=&quot;60%&quot;&gt;
    &lt;/div&gt;
      
    &lt;!-- Navigationsleiste --&gt;
    &lt;nav class=&quot;navbar navbar-expand-sm bg-dark navbar-dark&quot; &gt;
      &lt;div class=&quot;container col-md-12&quot;&gt;
        &lt;a class=&quot;navbar-brand text-warning&quot; href=&quot;../index.php&quot;&gt;DHBW Kino&lt;/a&gt;
        &lt;button class=&quot;navbar-toggler&quot; type=&quot;button&quot; data-toggle=&quot;collapse&quot; data-target=&quot;#collapsibleNavbar&quot;&gt;
          &lt;span class=&quot;navbar-toggler-icon&quot;&gt;&lt;/span&gt;
        &lt;/button&gt;
        &lt;div class=&quot;collapse navbar-collapse&quot; id=&quot;collapsibleNavbar&quot;&gt;
          &lt;ul class=&quot;navbar-nav me-auto&quot;&gt;
            &lt;li class=&quot;nav-item&quot;&gt;
              &lt;a class=&quot;nav-link&quot; href=&quot;../index.php&quot; style=&quot;color: #D3D3D3&quot;&gt;Startseite&lt;/a&gt;
            &lt;/li&gt;
            &lt;li class=&quot;nav-item&quot;&gt;
              &lt;a class=&quot;nav-link&quot; href=&quot;../anfahrt.php&quot; style=&quot;color: #D3D3D3&quot;&gt;Anfahrt&lt;/a&gt;
            &lt;/li&gt;
            &lt;li class=&quot;nav-item&quot;&gt;
              &lt;a class=&quot;nav-link&quot; href=&quot;../info.php&quot; style=&quot;color: #D3D3D3&quot;&gt;Über uns&lt;/a&gt;
            &lt;/li&gt;
            &lt;?php if($loggedIn) { ?&gt; &lt;li class=&quot;nav-item&quot;&gt; &lt;a class=&quot;nav-link&quot; href=&quot;../tickets.php&quot; style=&quot;color: #D3D3D3&quot;&gt;Tickets&lt;/a&gt; &lt;/li&gt; &lt;?php } ?&gt;
            &lt;?php if(hasRight('CONTROL_PANEL')) { ?&gt; &lt;li class=&quot;nav-item&quot;&gt; &lt;a class=&quot;nav-link&quot; href=&quot;../controlpanel.php&quot; style=&quot;color: #D3D3D3&quot;&gt;Verwaltung&lt;/a&gt; &lt;/li&gt; &lt;?php } ?&gt;
          &lt;/ul&gt;
        &lt;/div&gt;
        &lt;div class=&quot;collapse navbar-collapse&quot; id=&quot;collapsibleNavbar&quot;&gt;
          &lt;ul class=&quot;navbar-nav ms-auto&quot;&gt;
            &lt;?php if($loggedIn) { ?&gt; &lt;li class=&quot;nav-item&quot;&gt; &lt;a class=&quot;nav-link&quot; href=&quot;../profile.php&quot; style=&quot;color: #D3D3D3&quot;&gt;Profil&lt;/a&gt; &lt;/li&gt; &lt;?php } ?&gt;
            &lt;li class=&quot;nav-item&quot;&gt;
              &lt;?php
              if($loggedIn) {
                ?&gt;
                  &lt;a class=&quot;nav-link&quot; href=&quot;../logout.php&quot; style=&quot;color: #D3D3D3&quot;&gt;Log Out&lt;/a&gt;
                &lt;?php
              } else {
                ?&gt;
                  &lt;a class=&quot;nav-link&quot; href=&quot;../login.php&quot; style=&quot;color: #D3D3D3&quot;&gt;Log In&lt;/a&gt;
                &lt;?php
              }
              ?&gt;
            &lt;/li&gt;    
          &lt;/ul&gt;
        &lt;/div&gt;  
      &lt;/div&gt;
    &lt;/nav&gt;
  </code></pre>
  <p>AJAX success response: (my index.php)</p>
  <pre><code>&lt;!DOCTYPE html&gt;
    &lt;html lang=&quot;de&quot;&gt;
    &lt;head&gt;
      &lt;title&gt;DHBW Kino Website&lt;/title&gt;
      &lt;meta charset=&quot;utf-8&quot;&gt;
      &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1&quot;&gt;
      &lt;link href=&quot;css/style.css&quot; rel=&quot;stylesheet&quot;&gt;
  
      &lt;!-- Insert Favicon to make it show in Tab --&gt;
      &lt;link rel=&quot;shortcut icon&quot; type=&quot;image/x-icon&quot; href=&quot;../img/favicon.ico&quot;&gt;
  
      &lt;!-- Latest compiled and minified CSS --&gt;
      &lt;link href=&quot;https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta1/dist/css/bootstrap.min.css&quot; rel=&quot;stylesheet&quot; integrity=&quot;sha384-giJF6kkoqNQ00vy+HMDP7azOuL0xtbfIcaT9wjKHr8RbDVddVHyTfAAsrekwKmP1&quot; crossorigin=&quot;anonymous&quot;&gt;
      
      &lt;!-- jQuery library --&gt;
      &lt;script src=&quot;https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js&quot;&gt;&lt;/script&gt;
  
      &lt;!-- Popper JS --&gt;
      &lt;script src=&quot;https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js&quot;&gt;&lt;/script&gt;
      
      &lt;!-- Latest compiled JavaScript --&gt;
      &lt;script src=&quot;https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js&quot;&gt;&lt;/script&gt; 
  
      &lt;!-- Schriftart --&gt;
      &lt;script src=&quot;https://use.fontawesome.com/releases/v5.0.8/js/all.js&quot;&gt;&lt;/script&gt;
  
      &lt;!-- Bootstrap Table Pack --&gt;
      &lt;link rel=&quot;stylesheet&quot; href=&quot;https://unpkg.com/bootstrap-table@1.18.2/dist/bootstrap-table.min.css&quot;&gt;
      &lt;script src=&quot;https://unpkg.com/bootstrap-table@1.18.2/dist/bootstrap-table.min.js&quot;&gt;&lt;/script&gt;
      &lt;script src=&quot;https://cdnjs.cloudflare.com/ajax/libs/bootstrap-table/1.18.2/locale/bootstrap-table-de-DE.min.js&quot;&gt;&lt;/script&gt;
      
    &lt;/head&gt;
  
    &lt;!-- Titel/ Header der Website--&gt;
    &lt;div class=&quot;jumbotron container text-center&quot; style=&quot;margin-bottom:0&quot;&gt;
        &lt;img class=&quot;logo&quot; src=&quot;../img/logo.png&quot;  width=&quot;60%&quot;&gt;
    &lt;/div&gt;
      
    &lt;!-- Navigationsleiste --&gt;
    &lt;nav class=&quot;navbar navbar-expand-sm bg-dark navbar-dark&quot; &gt;
      &lt;div class=&quot;container col-md-12&quot;&gt;
        &lt;a class=&quot;navbar-brand text-warning&quot; href=&quot;../index.php&quot;&gt;DHBW Kino&lt;/a&gt;
        &lt;button class=&quot;navbar-toggler&quot; type=&quot;button&quot; data-toggle=&quot;collapse&quot; data-target=&quot;#collapsibleNavbar&quot;&gt;
          &lt;span class=&quot;navbar-toggler-icon&quot;&gt;&lt;/span&gt;
        &lt;/button&gt;
        &lt;div class=&quot;collapse navbar-collapse&quot; id=&quot;collapsibleNavbar&quot;&gt;
          &lt;ul class=&quot;navbar-nav me-auto&quot;&gt;
            &lt;li class=&quot;nav-item&quot;&gt;
              &lt;a class=&quot;nav-link&quot; href=&quot;../index.php&quot; style=&quot;color: #D3D3D3&quot;&gt;Startseite&lt;/a&gt;
            &lt;/li&gt;
            &lt;li class=&quot;nav-item&quot;&gt;
              &lt;a class=&quot;nav-link&quot; href=&quot;../anfahrt.php&quot; style=&quot;color: #D3D3D3&quot;&gt;Anfahrt&lt;/a&gt;
            &lt;/li&gt;
            &lt;li class=&quot;nav-item&quot;&gt;
              &lt;a class=&quot;nav-link&quot; href=&quot;../info.php&quot; style=&quot;color: #D3D3D3&quot;&gt;Über uns&lt;/a&gt;
            &lt;/li&gt;
             &lt;li class=&quot;nav-item&quot;&gt; &lt;a class=&quot;nav-link&quot; href=&quot;../tickets.php&quot; style=&quot;color: #D3D3D3&quot;&gt;Tickets&lt;/a&gt; &lt;/li&gt;            &lt;li class=&quot;nav-item&quot;&gt; &lt;a class=&quot;nav-link&quot; href=&quot;../controlpanel.php&quot; style=&quot;color: #D3D3D3&quot;&gt;Verwaltung&lt;/a&gt; &lt;/li&gt;         &lt;/ul&gt;
        &lt;/div&gt;
        &lt;div class=&quot;collapse navbar-collapse&quot; id=&quot;collapsibleNavbar&quot;&gt;
          &lt;ul class=&quot;navbar-nav ms-auto&quot;&gt;
             &lt;li class=&quot;nav-item&quot;&gt; &lt;a class=&quot;nav-link&quot; href=&quot;../profile.php&quot; style=&quot;color: #D3D3D3&quot;&gt;Profil&lt;/a&gt; &lt;/li&gt;           &lt;li class=&quot;nav-item&quot;&gt;
                              &lt;a class=&quot;nav-link&quot; href=&quot;../logout.php&quot; style=&quot;color: #D3D3D3&quot;&gt;Log Out&lt;/a&gt;
                          &lt;/li&gt;    
          &lt;/ul&gt;
        &lt;/div&gt;  
      &lt;/div&gt;
    &lt;/nav&gt;
  1
  </code></pre>