title: javascript retreive fetch response from a php
body: <p>I'm try to implement the paypal express checkout.
  So I implement the button and write the result in my database. Nothing exceptional, it's the script they gave.</p>
  
  <pre><code>&lt;script&gt;
  paypal.Buttons({
      createOrder: function(data, actions) {
        return actions.order.create({
          purchase_units: [{
            amount: {
              value: '0.01'
            }
          }]
        });
      },
      onApprove: function(data, actions) {
        return actions.order.capture().then(function(details) {
          // Call your server to save the transaction
          return fetch('recordDatabase.php', {
            method: 'post',
            mode: "same-origin",
            credentials: "same-origin",
            headers: {"Content-Type": "application/json"},
            body: JSON.stringify({
                orderID: data.orderID, 
                time: details.create_time, 
                status: details.status, 
                nom: details.payer.name.given_name, 
                prenom: details.payer.name.surname, 
                pays: details.payer.address.country_code, 
                valeur:details.purchase_units[0].amount.value
            })
          })
        });
      }
    }).render('#paypal-button-container');
  &lt;/script&gt;
  </code></pre>
  
  <p>The php to record in the database:</p>
  
  <pre><code>&lt;?php
  $link = connect();
  
  $date = date('Y-m-d H:i:s');
  //Receive the RAW post data.
  $contentType = isset($_SERVER["CONTENT_TYPE"]) ?trim($_SERVER["CONTENT_TYPE"]) : '';
  
  if ($contentType === "application/json") {
      //Receive the RAW post data.
      $content = trim(file_get_contents("php://input"));
      $decoded = json_decode($content, true);
  
      //If json_decode failed, the JSON is invalid.
      if(! is_array($decoded)) {
          //echo "error";
      } else {
          $name = $decoded['nom'];
          $time = $decoded['time'];
          $id = $decoded['orderID'];
          $stat = $decoded['status'];
          $pays = $decoded['pays'];
          $val = $decoded['valeur'];
  
          $secQuery = "INSERT INTO myDatabase(PSEUDO,PASSWORD,CONNECTION,INSCRIPTION,ANNIVERSAIRE,MAIL,IDPAYPAL,STATPAYPAL,NOMPAYER,PAYS,VALEUR) VALUES ('essai','123456',0,'$date','$time','email@mail','$id','$stat','$name','$pays','$val') ";
          if (mysqli_query($link,$secQuery)) {
              //echo "ok";
          } else {
              //echo "error";
          }
  
      }
  } else {
      //echo "error";
  }
  </code></pre>
  
  <p>So, the record in my database works fine, but my question is:</p>
  
  <p>How can I retrieve the echo error or ok in the javascript to confirm the user that everything is fine, or if an error happen.</p>
  
  <p>I tried another solution, to redirect the user from the php and add to the php:</p>
  
  <p><code>header("Location: confirmation web page");</code> or<br>
  <code>echo "&lt;script&gt;window.location = 'confirmation web page'&lt;/script&gt;";</code></p>
  
  <p>but both solution doesn't work. No redirection happen</p>