I do have a file on my local installed XAMPP which is called TEST.PHP. When i go to http://127.0.0.1/TEST.PHP and execute it, the script should post the values ID and NAME to the site http://otherdomain.com/post.php and put the output into DATA. This does not work because of the Same-Origin Policy. When i trace the packages i get an Error calles "NS_ERROR_DOM_BAD_URI". My question now is, is there anyway to make it possible anyways without needing to have access to http://otherdomain.com/?
TEST.PHP
<script>
$(window).load(function(){
var url = "http://otherdomain.com/post.php";
$.post(url,{id : "12", name : "John"}, function(data)
{
alert("It worked!");
});
});
</script>
UPDATE
I changed it now to the following set up. I have two files called SEND.PHP and PROXY.PHP. I send a request from SEND.PHP to PROXY.PHP and PROXY.PHP sent the actual request to OTHERDOMAIN.COM. When i execute SEND.PHP now(means i am pressing the button) i always get the result "Error: 403 Forbidden Access".
SEND.PHP
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
$.post("proxy.php", function(data,status){
alert("Data: " + data + "\nStatus: " + status);
});
});
});
</script>
</head>
<body>
<button>Send Data</button>
</body>
</html>
PROXY.PHP
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"http://otherdomain.com/data");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,"name=Jack&age=23");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$server_output = curl_exec ($ch);
curl_close ($ch);
if ($server_output == "OK") { echo "It Worked!"; } else { echo "Error: " . $server_output; }
?>