【发布时间】:2021-10-28 15:19:48
【问题描述】:
我是新手编码员。我正在尝试在我的前端 HTML 页面中插入 var cPrice。但是,它是未定义的,我不知道为什么。
///////////// 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();
【问题讨论】:
-
你能用 curl 或 postman 得到结果吗?
-
是的,结果是148.6
-
您的代码是否显示任何错误?
-
没有。我删除了 .currentPrice,现在它显示“成功”而不是未定义。
-
你的结果是错误的