I have a PHP file on a subdomain, and within that file, I want to use Javascript
and Ajax
to send information to a PHP file on the parent domain (to update my database). However, I receive the error that the request has been blocked by CORS
(which makes sense, I understand why). Is there a simple way to solve this?
I have tried putting document.domain = "example.com" in the javascript on the subdomain file, but obviously I can't put this in the file on the parent domain because it is a PHP file with no javascript. Just putting that line in the subdomain file has not worked.
file1: area1.example.com/settings.php
<?php
print '
<script type="text/javascript">
function UpdateTable(Info)
{
$.ajax({url: "https://example.com/ajax/update-table.php", type: "POST", data: {id: 1, info: Info}});
}
</script>';
?>
file2: example.com/ajax/update-table.php
<?php
$query = '
Update `Table`
SET `Table`.`field` = "'.$_POST['info'].'"
WHERE `Table`.`id` = '.$_POST['id'];
db_op($query);
?>
All I want is for the database to be updated, but I keep receiving the same CORS error. Can anyone help?