This problem is very common on webservices I suggest you study about CORS http://pt.wikipedia.org/wiki/Cross-origin_resource_sharing.
This is a problem that has to be solved both on the server and in your client application being a JS or other client.
To resolve 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 cool for you to access global variables such as $_SERVER directly strongly recommend some php package to do this, if possible a framework or mini framework for this service https://packagist.org/packages/symfony/http-foundation already help.
To solve this on the client side just enable CORS in jquery or at the http of the angle at 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 that’s any doubt leaves a comment there, vlw
Andre thanks for the answer, but I’m already using this method. The same works when the file is local and read a local file, or when it is on the server and read a file on the server. My problem is when the request is made from the local server to the web server.
– tassionoronha
<script type="text/javascript"> $(Document). ready(Function(){ $.get("http://www.tassionoronha.com.br/peixes.php", Function(data){ $("#answer1").html(date.text) }, "json") }); </script> <divid="answer1"></div>
– tassionoronha