title: Posting from local html/javascript website to an online PHP file
body: <p><strong>What I'm trying to do</strong></p>
  
  <p>Post from a local html/javascript website to an online PHP file. </p>
  
  <p><strong>Problem</strong></p>
  
  <p>When I attempt to utilise my below code, I keep receiving the below mentioned error. </p>
  
  <p><strong>Background:</strong></p>
  
  <p>This website is intended to run locally. As it's each user's choice which browser they use, I'm looking to discover an approach which could solve the above, without forcing browser policy modification onto each user. </p>
  
  <p>Is this possible, if so how?</p>
  
  <p><strong>Javascript code:</strong></p>
  
  <pre><code>$.ajax({
      type: 'POST',
      url: 'http://example.com/test.php',
      crossDomain: true,
      data: "my_request_is=foo",
      dataType: 'json',
      success: function(responseData, textStatus, jqXHR) 
      {
          console.log(responseData);
      },
      error: function (responseData, textStatus, errorThrown) 
      {
          console.warn(responseData, textStatus, errorThrown);
          alert('CORS failed - ' + textStatus);
      }
  });
  </code></pre>
  
  <p><strong>Php code (test.php):</strong></p>
  
  <pre><code>&lt;?php
  header('Access-Control-Allow-Origin: *');
  header('Access-Control-Allow-Methods: POST, GET, OPTIONS');
  header('Access-Control-Max-Age: 1000');
  header('Access-Control-Allow-Headers: Content-Type');
  echo json_encode(array("your_request_was" =&gt; $_POST['my_request_is']));
  ?&gt;
  </code></pre>
  
  <p><strong>Error:</strong></p>
  
  <p><a href="https://i.stack.imgur.com/qYqsW.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/qYqsW.png" alt="Error Image"></a></p>