没有重新加载页面的登录表单验证
我有一个登录表单,我想在不重新加载页面的情况下进行确认。我怎样才能做到这一点? AJAX或Express(NodeJS)?
<form class="login-form" method="POST" @submit.prevent>
<p>Login to the chat.</p>
<br>
<p>Login:</p> <input type="text">
<p>Password:</p> <input type="password">
</form>
回答如下:您应该先删除您的“表单”标签并添加一个按钮,以激活功能,例如“登录”
我建议使用axios:
在您的函数“登录”中写:
axios.post('/loginpath', {
name: 'Fred',
password: 'Flintstone'
})
.then(function (response) {
if(response == "ok")
{
window.location.replace("http://website/redirect);
})
.catch(function (error) {
console.log(error);
});
在服务器端,您捕获到类似这样的请求
app.post("/loginpath", (req,res) => {
res.send("ok")
})
您将需要暂停“ bodyparser”以从您的身体获取数据。安装bodyparser时,您可以使用req.body.name或req.body.password访问已提交的数据
没有重新加载页面的登录表单验证
我有一个登录表单,我想在不重新加载页面的情况下进行确认。我怎样才能做到这一点? AJAX或Express(NodeJS)?
<form class="login-form" method="POST" @submit.prevent>
<p>Login to the chat.</p>
<br>
<p>Login:</p> <input type="text">
<p>Password:</p> <input type="password">
</form>
回答如下:您应该先删除您的“表单”标签并添加一个按钮,以激活功能,例如“登录”
我建议使用axios:
在您的函数“登录”中写:
axios.post('/loginpath', {
name: 'Fred',
password: 'Flintstone'
})
.then(function (response) {
if(response == "ok")
{
window.location.replace("http://website/redirect);
})
.catch(function (error) {
console.log(error);
});
在服务器端,您捕获到类似这样的请求
app.post("/loginpath", (req,res) => {
res.send("ok")
})
您将需要暂停“ bodyparser”以从您的身体获取数据。安装bodyparser时,您可以使用req.body.name或req.body.password访问已提交的数据