[英]Node JS. Jade/Pug page is not rendered
我正在嘗試通過單擊選項卡按鈕使用SQL數據刷新表,但是它不起作用。
在app.js中:
app.post('/updateTable', function(req, res) {
var db = new sqlite3.Database('users.db');
db.serialize(function() {
db.all("SELECT * FROM user_info", function(err, rows) {
res.render('index', { title: 'Student Registration', rows: rows });
});
});
db.close();
});
在index.pug中:
#tabs-2.box
table
thead
tr#tabTit
th Name
th Birthday
th EduID
th EduGroup
th Phone
th Email
tbody
- for (var item in rows)
tr
td= rows[item].name
td= rows[item].date
td= rows[item].eduID
td= rows[item].gr
td= rows[item].phone
td= rows[item].email
在clien端JS中:
$(document).ready( function() {
$('#tabs, #tabs-2').tabs({
activate: function(event, ui) {
$.ajax({
type: 'POST',
url: '/updateTable'
});
}
});
});
成功處理了后請求,但“ res.render”不起作用。
我在哪里搞砸?
PS對不起,我的英語
您確定發帖請求已得到處理嗎? 您在聲明activate
函數,但從未調用它。
如果這不是問題,請嘗試返回res.render。 它成為了:
return res.render('index', { title: 'Student Registration', rows: rows });
最后! 它與ajax請求中的成功處理程序一起使用。 現在有動態刷新表。
呈現哈巴狗頁面“表格”
db.all("SELECT * FROM user_info", function(err, rows) {
res.render('table', { rows: rows });
});
成功處理程序
$.ajax({
type: 'GET',
url: '/updateTable',
success: function(data) {
$('#tabs-2').html(data);
}
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.