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

69
Views
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 answers
Answer question

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 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!