I 'm working at with XAMPP server at my home pc.My files are in xampp/htdocs/marfo I am trying to fetch some records in a booking database lying on xampp\mysql\data\marfo. Althought i can read all others tables of the same database (using different files at the same directory) this specific table gives me this error "Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at file:///C:/xampp/htdocs/marfo/booking.php. (Reason: CORS request not http)."
the code in js is:
function readres() {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
if (this.responceText != "NoResults") {
reservarray = JSON.parse(this.responseText);
// function to set whole site for this language
} else { return "Bad thing !!! Something went wrong .........." }
} else { return "Didn't found anything malaka.........." }
}
xmlhttp.open("GET", "booking.php", true);
xmlhttp.send();
}
and the code at PHP file:
$servername = 'localhost';
$username = 'root';
$password = '';
$dbname = 'marfo';
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed:" . $conn->connect_error);
}
$sql = "SELECT * FROM bookings";
$result = $conn->query($sql);
$counter = 0;
if ($result->num_rows > 0) {
// output reservations
while ($row = $result->fetch_assoc()) {
$reservarray = array(
"datefrom" . $counter => $row["datefrom"], "dateto" . $counter => $row["dateto"], "name" . $counter => $row["name"]
);
$counter = $counter + 1;
}
echo json_encode($reservarray);
} else {
echo 'No results';
}
$conn->close();```
any help appreciated....