router.get('/', function(req, res, next) {
res.render('demo5.html');//渲染的页面
});
router.post('/', function(req, res, next) {
res.send("要发送的数据");//要发送的数据
});
我在demo5.html中用ajax post请求发送表单数据后,想返回给原来的页面数据让ajax获取到数据,上面代码倒数第2行执行完直接转向如下图
怎么做才能使原来的页面不变又能让ajax获取的到数据,谢谢!
I wrote it according to your method.
res.send()
will not cause the page to jump. If I guessed correctly, your data is placed inform
. Submitting the form will cause the page to jump, and then the server will If the results inapp.post()
inres.send()
are returned to the new page, the problem you mentioned will occur. Just use ajax to submit data and there will be no problem.This is the value-passing method of get
You can call {{name}} to
on ejs