This problem is very common in webservices I suggest you study about CORS link .
This is a problem that has to be solved both on the server and in your client application being it a JS or another client.
To solve this on the server you can do as follows, just call this php function in your input file
function cors() {
// permite para qualquer origem
if (isset($_SERVER['HTTP_ORIGIN'])) {
header("Access-Control-Allow-Origin: *");
header('Access-Control-Allow-Credentials: true');
header('Access-Control-Max-Age: 86400'); // cache por 1 dia
}
// Essa parte cuida do preflight request
if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
header("Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS");
header("Access-Control-Allow-Headers: Accept, Content-Type");
exit(0);
}
echo "Você está com CORS!";
}
Remembering that it is not legal to access global variables like $ _SERVER directly strongly recommend some php package that does this, if possible a framework or mini framework for this service link already help.
To resolve this from the client side, just activate CORS in the jquery or http of the angle in which you prefer
$.ajax({
url: "http://example.com/minha/acao/",
type: "POST",
crossDomain: true,
data: {conteudopost: "algumacoisa"},
dataType: "json",
success: function (response) {
//sucesso
},
error: function (xhr, status) {
//erro
}
});
Basically this is any question leave a comment ai, vlw