Javascript 调用Ajax后如何在node.js中加载jade文件
在node.js应用程序中,我通过单击按钮创建一个Ajax类,并希望加载新的html文件。一切都很顺利,但是新的html文件没有加载 我在main.jade文件中进行如下ajax调用:Javascript 调用Ajax后如何在node.js中加载jade文件,javascript,jquery,ajax,node.js,express,Javascript,Jquery,Ajax,Node.js,Express,在node.js应用程序中,我通过单击按钮创建一个Ajax类,并希望加载新的html文件。一切都很顺利,但是新的html文件没有加载 我在main.jade文件中进行如下ajax调用: script(type='text/javascript'). $(document).ready(function(){ $(".login-button").click(function() { $.ajax({
script(type='text/javascript').
$(document).ready(function(){
$(".login-button").click(function() {
$.ajax({
method: "POST",
url: "http://localhost:3000/admin",
data: { name: "xyz", organization: "abcdz" }
})
router.post('/admin', function(req, res) {
res.render('summary', { name: req.body.name})
});
在点击登录按钮进行ajax调用后,我想加载summary.jade文件,但它并没有被加载,而是显示登录页面
我不知道该怎么做
app.js
发送html。如果需要呈现html,则必须为post
附加一个成功处理程序,并将内容注入dom
$.ajax({
method: "GET",
url: "http://localhost:3000/admin",
data: { name: "xyz", organization: "abcdz" }
success: function (data) {
//data is the resultant html when gets created by res.render()
// wanna show it, add it to the dom
$('.some-element').html(data);
}
});
res.render
发送html。如果需要,您必须为您的帖子附加一个onSuccess
处理程序,并将内容注入domok。。。但这一个就像在同一个html页面中,我应该有一些元素类,但我的要求是我想加载另一个页面。。我不想在同一页上显示。在这种情况下,不要执行res.render('summary',{name:req.body.name})
,而是执行res.redirect
到路由。我尝试了res.redirect,但这对merouter.post('/admin',function(req,res){res.redirect('www.google.com');})也不起作用;这能行吗?不,这也不行。。。在日志中,请求正在发送,响应也正在发送,但在浏览器页面上没有更改
$.ajax({
method: "GET",
url: "http://localhost:3000/admin",
data: { name: "xyz", organization: "abcdz" }
success: function (data) {
//data is the resultant html when gets created by res.render()
// wanna show it, add it to the dom
$('.some-element').html(data);
}
});