I'd like to post data from domain1.com to domain2.com using AJAX, but my request fails.
Here's is my code on domain1.com:
$.ajax({
    type: 'POST',
    url: 'https://domain2.com/payment/api/server',
    crossDomain: true,
    data: {
            Name: $("#name").val().trim(), 
            Email: $("#email").val().trim()
          },
    dataType: 'json',
    success: function(data) {
        alert('Success');
    },
    error: function (data) {
        alert('POST failed.');
    }
});
and here's my server side code on domain2.com:
switch ($_SERVER['HTTP_ORIGIN']) {
  case 'http://domain1.com/api/': case 'http://domain1.com/api/':
    header('Access-Control-Allow-Origin: '.$_SERVER['HTTP_ORIGIN']);
    header('Access-Control-Allow-Methods: GET, PUT, POST, DELETE, OPTIONS');
    header('Access-Control-Max-Age: 1000');
    header('Access-Control-Allow-Headers: Content-Type, Authorization, X-Requested-With');
  break;
}
$name = $_POST['Name'];
echo $name; // Just to check if I receive the value from index.php
 
     
     
    