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

78
Views
La solicitud Ajax de PHP no me devuelve una matriz

Estoy tratando de devolver una matriz desde un script PHP en Ajax, sin embargo, parece que no funciona, me devuelve una cadena en lugar de una matriz. Estoy usando CodeIgniter Framework, ahí está mi código .php:

 public function get_form(){ $donneesModel = new Mdonnees(); $result = $donneesModel->getAll(); $data=array( 'chartDate' => array(), 'chartTemp' => array(), ); foreach ($result as $row) { $data['chartDate'][] = date("d/m", strtotime($row['date'])); $data['chartTemp'][] = $row['temperature']; } print json_encode($data); }

Y ahí está mi solicitud de Ajax:

 $.ajax({ url:"Cdonnees/get_form", method:"GET", success:function(data) { console.log(data); .... .... }

Mi función getAll () simplemente selecciona todo de la base de datos, sin embargo, solo estoy usando la columna de temperatura y fecha.

Debería devolverme un Array como este , pero me devuelve este .

¿Puedes ayudarme o darme alguna pista de lo que está pasando?

Tuyo sinceramente,.

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Necesita analizar el JSON en Javascript:

 $.ajax({ url:"Cdonnees/get_form", method:"GET", success:function(data) { //this will print the data console.log(JSON.parse(data)); // save it to a variable and can use it in the rest of the program const pareseData = JSON.parse(data); .... .... } });

y debería funcionar.

over 4 years ago · Santiago Trujillo Report

0

Prueba esto

 $.ajax({ url:"Cdonnees/get_form", method:"GET", success:function(data) { $.each(data, function (key, value) { console.log(key) console.log(value) }) } });
over 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!