导航栏未在所有页面上显示

时间:2020-01-11 07:53:34

标签: html nav

我想在所有页面上显示导航栏,但是我不想将相同的代码复制粘贴到所有html文件中。我试图将导航条形码放到另一个文件Navigation.html中,然后使用脚本将其加载回index.html,但是它不起作用。有人知道我在哪里犯错了吗?

这是navigation.html:

const passport = require("passport");
const User = require("../routes/AdminSchema")

passport.serializeUser(function(user, done) {
    console.log('i am serializing the user');
    done(null, user.username);
});

passport.deserializeUser(function(username, done) {
    console.log('i am de-serializing the user');
    User.findOne({username}).lean().exec((err,user) => {
        done(err, user);
    });
});

//import strategy
const AdminLoginStrategy = require("./AdminLoginStrategy");

passport.use('local-adminSignin',AdminLoginStrategy);


module.exports = passport;

这是index.html:

const Strategy = require("passport-local").Strategy;
const User = require("../routes/AdminSchema")
const bcrypt = require("bcryptjs")

const LoginStrategy = new Strategy({passReqToCallback:true},function(req,username,password,done){

        User.findOne({username}).lean().exec((err,user) => {
            if(err){
                return done("db error idk bro",null)
            }
            if(!user){
                return done("user not found!",null)
            }

            const isPasswordValid = bcrypt.compareSync(password, user.password);

            if(!isPasswordValid){
                return done("username or password not valid!",null)
            }

            return done(null,user)
    })
})


module.exports = LoginStrategy

2 个答案:

答案 0 :(得分:1)

您可以使用ajax加载内容

<script>
	$(function(){     
		$.ajax({  
		  type: "GET",
		  url: "navigation.html",  
		  dataType: "html",
		  success: function(answer) {  
			$("body").append(answer);  
		  },
		  error: function(){
			alert("failed call!!!");
		  } 
		}); 
		return false;  
	});
</script> 

答案 1 :(得分:0)

如果导航栏将成为您网站的标题,则传统上将其命名为header.html。

我更喜欢使用.php而不是.html来相互链接页面。这是我详细解释的链接:

[How to include an external HTML-Head?