1.server端:
ClientController.prototype.ordertoapp = function(req, res, next)
{
var locals = {
cas_user: casuser,
title: 'order',
page_title: '待审批'
};
OrderDao.query(function(err, result) {
locals.orders = result;
res.render('client/order', locals)
})
}
2.client
<div class="portlet-body" id="container">
JS:
var $orders = $('<div class="table-scrollable">\
<table class="table table-hover" id="headerTable">\
<thead>\
<tr>\
<th>\
序号\
</th>\
<th>\
姓名\
</th>\
<th>\
状态\
</th>\
<th>\
</th>\
</tr>\
</thead>\
<tbody>\
<% for(var i=0;i<orders.length;i++){ %>\
<tr>\
<td>\
<%=orders[i].id%>\
</td>\
<td>\
<%=orders[i].empname%>\
</td>\
<%if(orders[i].status ==1){%>\
<td>\
已提交\
</td>\
<%}
if(orders[i].status ==2){%>
<td>
已通过
</td>
<%}
%>\
<td>\
<button onClick="approve(<%=orders[i].id%>)">通过</button> \
</td>\
</tr>\<%}%>\
</tbody>\
</table>\
</div>');
$('#container').html($orders);
Ajax:
$.ajax({
type: 'POST',
dataType: 'json',
url: '../rest/updateorder',
data: mydata1,
headers: {
'Content-Type': 'application/json'
},
success: function(res) {
console.log(res);
if (res.status == "ok") {
//这里如何处理才能局部刷新这条数据更新后的状态?
} else {
alert("error!")
}
},
error: function(data) {
alert("网络异常");
}
});
之前瞎说了一波.....
ejs
渲染以后不能动态修改,还是要靠ajax
...根据你的代码改了一下,上代码,代码测过了没问题,图我就不放了,你可以自己测一下。ejs
中:Node.js
控制器中:Ajax
: