-2

Using the below Ajax call in my local machine.

$.ajax({
    type: "POST",
    data: {
        id : '1234',
        name : 'test',
    },
    url: "https://testdomain.com/test.php",
    success: function (response) {
        console.log(response);
        } else {
            console.log('error);
        }
    }
});

But getting cors error

access to XMLHttpRequest at 'https://testdomain.com/test.php' from origin 'http://localhost/' has been blocked by CORS policy: The 'Access-Control-Allow-Origin' header contains the invalid value.

M0nst3R
  • 5,186
  • 1
  • 23
  • 36

1 Answers1

0

You need to ensure that the server at "https://testdomain.com" includes the appropriate "Access-Control-Allow-Origin" header in its response to your AJAX request. This header indicates which origins are allowed to access the server's resources.

If you have control over the server, you can modify the PHP script ("test.php") to include the following header in the response:

header("Access-Control-Allow-Origin: http://localhost/");

Layhaunt
  • 61
  • 1
  • 3