简体   繁体   English

完全不做任何事情的请求

[英]Request that does absolutely nothing

I am trying to make a button which triggers a request to render a login page.我正在尝试制作一个按钮来触发呈现登录页面的请求。 I want to limit the login page to only the admins of my project.我想将登录页面限制为仅限我的项目管理员。 I have their ip addresses and use those to check against those from the database.我有他们的 IP 地址,并使用它们来检查数据库中的 IP 地址。 If the ip matches, I want the login page to be rendered, but if it doesen't match, then I want the page to be as it is.如果 ip 匹配,我希望呈现登录页面,但如果不匹配,则我希望页面保持原样。 I don't want page reload or page redirection.我不想要页面重新加载或页面重定向。 I want it like the button is not working at all.我想要它就像按钮根本不起作用一样。 The page should not be trying to fetch a response.该页面不应试图获取响应。

I want something like this -我想要这样的东西 -

I have a button which is a submit form, it contains the ip of the user.我有一个按钮,它是一个提交表单,它包含用户的 ip。

app.post("/something",function(req,res){
  Admins.findOne({userIP:req.body.userIP},function(err,foundItem){
     if(!err){
       if(foundItem){
         res.render("login");
       }else{

       }
  });
});

I am not sure what code needs to go in the else section.我不确定else部分需要哪些代码。 res.end() is not working for me as a blank white page is shown if I use that. res.end()对我不起作用,因为如果我使用它会显示空白页。 I want the page to be as it is and where it is.我希望页面保持原样以及它所在的位置。

Please help guys!请帮助伙计们! Thanks in advance.提前致谢。

First this is not node js problem.首先,这不是节点 js 问题。 This is normal Form submit and basic html stuff.这是正常的表单提交和基本的 html 内容。 Second When you click on submit button automatically refreshes the client page and wait for new rendered page from server .第二,当您单击提交按钮时,会自动刷新client页面并等待来自server新呈现页面。

So basically what you need to do is render the same page where you have implemented the Form with action attribute.所以基本上你需要做的是呈现你已经实现了带有 action 属性的表单的页面。

(or) (或者)

You have to add onsubmit attribute in Form tag with a javascript function where you need to call an node js api and in node js you need to res.send({status:true (or) false}) which when you get in response from api call you conditionally stay or go to login page.您必须使用 javascript 函数在 Form 标签中添加 onsubmit 属性,您需要在其中调用节点 js api 并且在节点 js 中您需要res.send({status:true (or) false}) ,当您收到response时api 调用你有条件的停留或进入登录页面。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM