• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
    • Questions
    • Teachers
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

441
Views
Cómo declarar una variable en axios get json

Estoy usando axios.get para recuperar el elemento que quiero, y regresa correctamente con los datos json que se muestran a continuación: ingrese la descripción de la imagen aquí

Va bien, con [ y { perfectamente asignados. Aquí está mi deber, quiero recuperar un elemento de columna (este json solo tiene una plantilla), digamos OrederReferencePreffix, devuelve undefined en lugar de [[\t ... Probé estas declaraciones a continuación:

 var attempt_one= json_only[0].InvoiceNumberPreffix; //undefined var attempt_two= response.data.InvoiceNumberPreffix; //undefined var attempt_three= response.data[0].InvoiceNumberPreffix; //undefined var attempt_four= json_only.InvoiceNumberPreffix; //undefined

El php devuelve el correcto como arriba, y en js

 axios.get('http://localhost/backend/get_templete.php', { params: { clciked_cpy: cpy } }) .then(function(response) { //attempt above, need to put my ans in here; tried var json_only = pre_cpy_cut.exec(response.data.toString()); console.log("=]" + json_only); } #reponse.data

en caso de que necesite, php:

 $json = array(); while($row = mysqli_fetch_assoc($result)) { $json[] = $row; } mysqli_free_result($result); echo json_encode( $json, JSON_UNESCAPED_SLASHES ); //return as same as the picture above

#response.data ya me da json y cosas para mí. ¿Por qué todavía no devuelve los datos de columna que quiero? Como hacer eso.

almost 3 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Creo que podría dar más información sobre su código, pero por lo que entendí, no está manipulando el JSON correctamente. Debe analizar los datos recuperados por la solicitud axios. Probar:

 axios.get('http://localhost/backend/get_templete.php', { params: { clciked_cpy: cpy } }) .then(function(response) { const parsedResponse = JSON.parse(response.data) // now you can access correctly the response data. console.log(parsedResponse.anyVariableYouWant) })
almost 3 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 Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error