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

133
Views
Cómo recuperar datos json de php

quiero recuperar datos json de php con ajax y enviarlos para la prueba. Pero no funcionó.

Cliente index.php

 <html> <head> <title>kakak</title> </head> <body> <p id="demo"></p> <script> var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { myObj = JSON.parse(this.responseText); document.getElementById("demo").innerHTML = myObj.name; } }; xmlhttp.open("GET", "json.php", true); xmlhttp.send(); </script> </body> </html>

Y esto es json.php ya tiene objeto.

 <?php $myArray = ["name" => "john", "age" => 30, "city" => "Japan"]; $myObj = json_encode($myArray); ?>

Quiero recuperar el nombre del objeto pero no genera nada.

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Debe hacer eco de la cadena JSON en el código PHP.

 echo $myObj;

El código final sería:

 <?php $myArray = ["name" => "john", "age" => 30, "city" => "Japan"]; $myObj = json_encode($myArray); echo $myObj; // or directly // echo json_encode($myArray); ?>
about 4 years ago · Santiago Trujillo 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!