Arraglando la api para que no de error de cors
This commit is contained in:
parent
18e88f331e
commit
701e909169
|
|
@ -1,5 +1,7 @@
|
||||||
<?php
|
<?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) ---
|
// --- 1. Database Configuration (Example with external config) ---
|
||||||
// In a real scenario, this would come from a file outside the web root.
|
// 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
|
http_response_code(200); // OK
|
||||||
echo json_encode($datos);
|
echo json_encode($datos);
|
||||||
} else {
|
} else {
|
||||||
// It's usually fine to return 200 OK with an empty array or a specific message
|
http_response_code(200);
|
||||||
// if no data is found, rather than a 404, unless it signifies a resource that
|
echo json_encode([]); // array vacío
|
||||||
// *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"]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// --- 5. Close Resources ---
|
// --- 5. Close Resources ---
|
||||||
$stmt->close();
|
$stmt->close();
|
||||||
$conn->close();
|
$conn->close();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue