페이지에서 다른 페이지로 검색하려면 일부보기 엔진을 사용해야합니다.
예 예 로그인 옥 (pug) 파일이 있습니다. "login.pug"file.When이 "/ 로그인"API는이 파일에서 호출됩니다
doctype html
html
head
script(src='https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js')
body
p
| Username
input(type='text', name='username' ,id='name')
p
| Password
input(type='password', name='password' ,id='password')
p
input(type='Submit', value='Login' onclick="login()")
|
a(href='http://localhost:8000/register') New Register
p
#{error}
script.
function login(){
$.post("http://localhost:8000/login",
{
username:document.getElementById("name").value,
password:document.getElementById("password").value,
},
function(data, status){
if(data.success===true){
window.location="http://localhost:8000/welcome"
}
else{
window.location="http://localhost:8000/"
}
});
}
그래서이되고, 내 서버 API (/ 로그인 API)
app.post('/login', function(req, res, next) {
checkExistanceOfuser(req.body.username, req.body.password, function(err, flag, data) {
console.log(err);
if (err) {
res.send({
err: 'SOME_DATABASE_ERROR'
})
} else {
if (flag) {
req.session.user = data;
res.send({
success: true,
message: 'Login Success'
})
} else {
res.send({
success: false,
message: 'Invalid Credentials'
});
}
}
})
});
에 따라 충돌합니다 post response` "window.location"뷰를 변경합니다. 예를 들어, 로그인에 성공 응답 후에, 나는이 /welcome
API에 GET 요청을 호출 지금
http://localhost:8000/welcome
에 보낼 수 있습니다.이 파일을 서버에 씁니다.
이렇게하면보기를 변경할 수 있습니다.
아마도 도움이 될 것입니다.
당신은'GET/brand'을 시도하고 있습니까? –
질문을 경로로 업데이트하십시오. –
사용중인'Express '버전은 무엇입니까? –