Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

74
Vistas
Using AJAX calls to perform create/update/delete operations in a single file instead of 3 different

I'm using Javascript to make XMLHttpRequests to various PHP files across my app, such as add.php, update.php, and delete.php. It feels redundant to have (3) different files being called. Is there a way I can put all these 3 files, add/update/delete, inside a single PHP file, like "main_operations.php", and then just make XMLHttpRequests to that single file each time, and have some sort of logic that only executes the part of the file I need? Example, maybe I can set a session variable in the xmlhttpprequest, like $_SESSION['ad_operation'] and then in the "main_operations.php" file use that variable to only run the ad operation?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can do it as Chris P said, it is as simple as that.

Example:-

$.post("url",{ action: "update/delete/add", id : "some_ID"},
  function(data,success){//Do something});

PHP file

<?php 
 if(isset($_POST['action'])){
   if($_POST['action'] == "add"){
   //Do add operation
   }
   else if($_POST['action'] == "update"){
   //Do update operation
   }
   else if($_POST['action'] == "delete"){
   //Do delete operation
   }
 }
?>

This helps you to handle the request and control the response.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda