title: Switching to https messed up my ajax calls
body: <p>since I uploaded my project to a webhosting I am facing the following issue:
  whenever I send an ajax request I get this error: POST https://_ DOMAIN _ /backend/login.backend.php 500</p>
  <p>apparently the google API works as I get all the data on php but the mysql requests never get through. It could be something about switching from http to https as it used to work perfectly on my localhost and now once I uploaded it, it does not work anymore.</p>
  <pre class="lang-js prettyprint-override"><code>            &lt;script src='https://apis.google.com/js/api:client.js'&gt;&lt;/script&gt;
              &lt;script&gt;
                  var googleUser = {};
                  var startApp = function() {
                      gapi.load('auth2', function(){
                      auth2 = gapi.auth2.init({
                          client_id: 'MY_ID_IS_HERE.apps.googleusercontent.com',
                          cookiepolicy: 'single_host_origin',
                          //scope: 'https://www.googleapis.com/auth/user.addresses.read',
                      });
                      attachSignin(document.getElementById('customGoogleButton'));
                      });
                  };
                  function attachSignin(element) {
                      auth2.attachClickHandler(element, {}, onLogin, onFail)
                  }
  
                  function onLogin(googleUser) {
                      var profile = googleUser.getBasicProfile();
                      var id_token = googleUser.getAuthResponse().id_token;
                  
                      var xhr = new XMLHttpRequest();
                      xhr.open('POST', 'backend/login.backend.php'); // link
                      xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
                      xhr.onload = function() {
                          console.log('Signed in:' + xhr.responseText);
                          //window.location.reload();
                      };
                      xhr.send('idtoken=' + id_token);
                  }
                  function onFail(error) {
                      console.log(error);
                  }
                  startApp();
              &lt;/script&gt;
  </code></pre>
  <pre class="lang-php prettyprint-override"><code>    require_once $_SERVER['DOCUMENT_ROOT'].'/vendor/autoload.php';
      include_once $_SERVER['DOCUMENT_ROOT'].&quot;/db/config.php&quot;;
  
      //$jwt = new \Firebase\JWT\JWT;
      //$jwt::$leeway = 10;
  
      if (!isset($_POST[&quot;idtoken&quot;])) {
          exit();
      }
      $id_token = $_POST[&quot;idtoken&quot;];
      $CLIENT_ID = 'MY_ID_IS_HERE';
  
      $client = new Google_Client(['client_id' =&gt; $CLIENT_ID]); 
      $payload = $client-&gt;verifyIdToken($id_token);
      if ($payload) {
  
          //log in
          session_start();
          
          $_SESSION['userFirstName'] = $payload[&quot;given_name&quot;];
          $_SESSION['userLastName'] = $payload[&quot;family_name&quot;];
          $_SESSION['userFullName'] = $payload[&quot;name&quot;];
          $_SESSION['email'] = $payload[&quot;email&quot;];
          $_SESSION['user_image'] = $payload[&quot;picture&quot;];
          
                  
          $email = mysqli_real_escape_string($conn, $payload[&quot;email&quot;]);
          $first = mysqli_real_escape_string($conn, $payload[&quot;given_name&quot;]);
          $last_name = mysqli_real_escape_string($conn, $payload[&quot;family_name&quot;]);
          $user_image = mysqli_real_escape_string($conn, $payload[&quot;picture&quot;]);
  
          $stmt = $conn-&gt;prepare('SELECT id from users WHERE email= ?');
          $stmt-&gt;bind_param('s', $_SESSION['email']);
          $stmt-&gt;execute();
          $result = $stmt-&gt;get_result();
          $data = $result-&gt;fetch_assoc();
          if (empty($data)) { 
              $sql = &quot;INSERT INTO users (first_name, last_name, user_image, email) VALUES (?, ?, ?, ?);&quot;;
          } else {
              $sql = &quot;UPDATE users SET first_name = ?, last_name = ?, user_image = ? WHERE email = ?;&quot;;
          }
          mysqli_query($conn, $sql);
          $stmt = mysqli_stmt_init($conn);
          if (!mysqli_stmt_prepare($stmt, $sql)) {
              echo &quot;SQL ERROR&quot;;
          } else {
              mysqli_stmt_bind_param($stmt, &quot;ssss&quot;, $first, $last_name, $user_image, $email);
              mysqli_stmt_execute($stmt);
          }
          if (empty($data)) {
              $stmt = $conn-&gt;prepare('SELECT id from users WHERE email= ?');
              $stmt-&gt;bind_param('s', $_SESSION['email']);
              $stmt-&gt;execute();
              $result = $stmt-&gt;get_result();
              $data = $result-&gt;fetch_assoc();
          }
          $_SESSION['user_id'] = $data['id'];
          exit();
      
      } else {
          echo &quot;&lt;h1&gt;ERROR&lt;/h1&gt;&quot;;
      }
  
  </code></pre>