I am using a server apache by XAMPP, the server is hosted on my machine, but when I try to make an ajax request I get the following error message:
Cross origin requests are only supported for protocol schemes: http, data,
chrome, chrome-extension, https.
Here are the code files I'm using:
PHP:
<?php
$servername = "localhost";
$username = "bioManager";
$password = "@manager@bioDB";
$dbname = "biodb";
// Cria conexão
$conn = new mysqli($servername, $username, $password, $dbname);
// Verifica conexão
if ($conn->connect_error) {
die("Erro de conexão: " . $conn->connect_error);
}
$result = mysqli_query($conn, "SELECT * FROM dominios");
$dados = array();
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
$row = array_map('utf8_encode', $row);
array_push($dados, $row);
}
echo json_encode($dados);
}
$conn->close();
?>
Javascript:
function carregaDominios(){
$.ajax({
method: "POST",
url: "../PHP/carregaDominios.php",
success: function(result){
alert(result);
}
});
}