Arraglando la api para que no de error de cors

This commit is contained in:
Tatiana Villa Ema 2026-02-04 19:08:29 +01:00
parent 18e88f331e
commit 701e909169
1 changed files with 6 additions and 6 deletions

View File

@ -1,5 +1,7 @@
<?php
header('Content-Type: application/json');
// Permitir solicitudes desde cualquier origen (CORS)
header("Access-Control-Allow-Origin: *");
header('Content-Type: application/json; charset=utf-8');
// --- 1. Database Configuration (Example with external config) ---
// In a real scenario, this would come from a file outside the web root.
@ -74,13 +76,11 @@ if ($result->num_rows > 0) {
http_response_code(200); // OK
echo json_encode($datos);
} else {
// It's usually fine to return 200 OK with an empty array or a specific message
// if no data is found, rather than a 404, unless it signifies a resource that
// *should* exist but doesn't. For a query, 200 OK is typical.
http_response_code(200); // OK
echo json_encode(["message" => "No hay datos para la ciudad especificada"]);
http_response_code(200);
echo json_encode([]); // array vacío
}
// --- 5. Close Resources ---
$stmt->close();
$conn->close();