i'm trying to do a request to a php file. I catch the longitude and latitude from a function in Maps API, and use AJAX to save this points in a MySQL database.
AJAX
function salvaPonto(latitude, longitude){
$.ajax({
type: "GET",
data: {latitude: latitude,longitude: longitude},
url: "http://localhost/dados/salvaPonto.php",
datatype: 'JSONp',
success: function(data) {
alert("ok");
},
error: function(data){
alert("erro");
}
});
}
PHP File
<?php
header("Access-Control-Allow-Origin", "*");
error_reporting(0);
$latitude = $_GET['latitude'];
$longitude = $_GET['longitude'];
$conn = mysql_connect('localhost', 'root', '') or die ('Erro de conexão com o banco de dados');
mysql_select_db('app') or die ('Erro ao selecionar banco de dados');
$myquery = "INSERT INTO pontos(latitude, longitude) VALUES ('".$latitude."', '".$longitude."');";
$result = mysql_query($myquery) or die("Query error:".mysql_error());
mysql_close($conn);
echo 1;
?>
Error:
XMLHttpRequest cannot load http://localhost/dados/salvaPonto.php?latitude=-22&longitude=-43. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.