Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

260
Views
¿Cómo proceso dos solicitudes a la misma dirección?

¿Cómo puedo tramitarlos para poder utilizar los datos de ambas solicitudes? interfaz de usuario:

 async function getSpecialties(){ let res = await fetch ('http://server-npk-web-core/specialties'); let specialties = await res.json(); }) } async function getSubjectsSpecial(){ let res = await fetch ('http://server-npk-web-core/specialties'); let subjectsSpecial = await res.json(); }) }

BLL: index.php

 if($method === 'GET'){ if($type === 'subjects'){ getSubjects($pdo); } elseif($type === 'specialties'){ getSpecialties($pdo); getSubjectsSpecial($pdo); }

especialidades.php

 function getSpecialties($pdo){ $specialties = 'SELECT * FROM `specialties`'; $stmt = $pdo -> query($specialties); while ($special = $stmt->fetch()){ $specialtiesList[] = $special; } echo json_encode($specialtiesList); } function getSubjectsSpecial($pdo){ $subjectsSpecial = 'SELECT `subjects`.`title` FROM `subjects` WHERE `id_specialties` = 2'; $stmt = $pdo -> query($subjectsSpecial); while ($subjectSpecial = $stmt->fetch()){ $subjectsSpecialList[] = $subjectSpecial; } echo json_encode($subjectsSpecialList); }

PD: No me golpeen con palos, estoy aprendiendo solo -_-

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Para usar el mismo endpoint para procesar dos o más solicitudes diferentes, debe proporcionar los medios por los cuales el servidor puede elegir las acciones apropiadas a tomar. Como sus solicitudes de fetch se realizan mediante GET , puede proporcionar un parámetro de cadena de consulta que luego se usa en el lado del servidor para bifurcar la lógica del programa. Por ejemplo:

 <?php //------------------------------- //server-npk-web-core/specialties //------------------------------- function getSpecialties($pdo){ $specialties = 'SELECT * FROM `specialties`'; $stmt = $pdo -> query($specialties); while ($special = $stmt->fetch()){ $specialtiesList[] = $special; } echo json_encode($specialtiesList); } function getSubjectsSpecial($pdo){ $subjectsSpecial = 'SELECT `subjects`.`title` FROM `subjects` WHERE `id_specialties` = 2'; $stmt = $pdo -> query($subjectsSpecial); while ($subjectSpecial = $stmt->fetch()){ $subjectsSpecialList[] = $subjectSpecial; } echo json_encode($subjectsSpecialList); } if( !empty( $_GET['action'] ) ){ switch( $_GET['action'] ){ case 'specialties': getSpecialties($pdo) break; case 'subjectsspecial': getSubjectsSpecial( $pdo ); break; default: echo 'Error'; break; } } ?>

Y las solicitudes de fetch modificadas con un nuevo parámetro de cadena de consulta

 <script> async function getSpecialties(){ let res = await fetch ('http://server-npk-web-core/specialties?action=specialties'); let specialties = await res.json(); }) }; async function getSubjectsSpecial(){ let res = await fetch ('http://server-npk-web-core/specialties?action=subjectsspecial'); let subjectsSpecial = await res.json(); }) }; </script>
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!