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

153
Views
La respuesta de Ajax no está definida

Soy un codificador novato. Estoy tratando de insertar el var cPrice en mi página HTML de front-end. Sin embargo, no está definido y no puedo entender por qué.

 ///////////// Display Pop-up finciton ////////////////// //Start// $('#button1').on('click', function() { // Show the popup $('#openPopup').show(); // Get the symbol and name and show it in the popup const symbolID = document.getElementById("symbolSearch").value.toUpperCase(); document.getElementById("currentSymbol").innerHTML = symbolID; $.get("http://localhost:5000/placeOrder", function(err, price) { console.log(price.currentPrice); var cPrice = price.currentPrice // On the server-side it prints the correct value. console.log(cPrice) // However, here the front-end value is undefined. if (err) { console.log(err) } else { document.getElementById("currPrice").innerHTML = cPrice } }); // Execute the function for retrieving the price //userAction();
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Lea los documentos: jQuery.get() para la devolución de llamada de la función de success :
el primer argumento son los datos de PlainObject

jQuery.get( url [, data ] [, success ] [, dataType ] )
éxito fn
Tipo: función ( datos , estado de texto, jqXHR)
Una función de devolución de llamada que se ejecuta si la solicitud tiene éxito. Obligatorio si se proporciona dataType, pero puede usar null o jQuery.noop como marcador de posición.

También hay un

Aviso de desaprobación :
Los métodos de devolución de llamada jqXHR.success(), jqXHR.error() y jqXHR.complete() se eliminan a partir de jQuery 3.0 . Puede usar jqXHR.done(), jqXHR.fail() y jqXHR.always() en su lugar.

por lo tanto, será mejor que vaya con un código más legible usando .done() y .fail() :

 $.get("http://localhost:5000/placeOrder") .done((data) => { console.log(data); console.log(data.currentPrice); }) .fail((jqXHR, textStatus, errorThrown) => { console.log(jqXHR); });
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!