我需要从一个输入表格发送一个值到的NodeJS服务器,其触发的计算以该值和需要更新与在客户端的计算的结果的p元素的p元件。更新从的NodeJS功能
这怎么办?
这是我有:
//服务器端:
app.post('/calculate/:id', function(req, res){
var title = 'Tax Calculation';
var tax= taxcalculation(req.params.id);
res.render('index', {
title: title,
tax: tax,
});
});
//客户端:
var income= document.getElementById("income");
var tax = document.getElementById("tax")
$(income).on('change', function() {
console.log("changed");
$.ajax({
type: 'POST',
url: '/calculate/'+income.value,
success: function() {
$('#tax').html('<%= tax %>');
},
error: function() { // if error occured
alert("Error occured, please try again");
},
});
});
我能够与页面的刷新,更新p元素。我怎么能做到这一点,而不刷新页面? – rlacle
当你可以做这样的事情'的document.getElementById(“yourParagraph”)的innerHTML = response.data响应;' –