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

322
Views
how to Receive JSON data sent by ajax in PHP

I have the data that want sent to backend, its look like

function lihat(){
    let id = "12345678";
    let profile = [{name:"dave", department : "Engginering"},
                   {name:"Tedd", department : "Engginering"}]
    $.ajax({
        type:'POST',
        url:'pages/dashboard/dashboard_be.php'
        data:{
            cekload  : true,
            keys     : id,
            dataList : profile 
        },
        success:function(data){
            console.log(data);
        }
   })

the question, how can I receive all of datas sent by ajax in php script this what I've tried

    $id      = $_POST['keys'];
    $cekload = $_POST['cekload'];
    $data    = json_decode($_POST['dataList'];);

   //I wanna parsing the dataList object and then loop it, how to make it ?

thanks, before

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

0

If you're trying to send/receive javascript objects, you need to convert the object to a string before sending and decode it back in php (into an array maybe) before reading.

<script>
    let id = "12345678";
    let profile = [{name:"dave", department : "Engginering"},
                   {name:"Tedd", department : "Engginering"}]
    $.ajax({
        type:'POST',
        url:'pages/dashboard/dashboard_be.php',
        data:{
            cekload  : true,
            keys     : id,
            dataList : JSON.stringify(profile) 
        },
        success:function(data){
            console.log(data);
        }
   });
</script>

PHP code:

<?php 
$id = $_POST['keys'];
$cekload = $_POST['cekload'];
$data = json_decode($_POST['dataList'], true);

echo $id;
echo $cekload;
print_r($data);
?>
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!