简体   繁体   中英

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. 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. 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.

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. res.end() is not working for me as a blank white page is shown if I use that. 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. This is normal Form submit and basic html stuff. Second When you click on submit button automatically refreshes the client page and wait for new rendered page from server .

So basically what you need to do is render the same page where you have implemented the Form with action attribute.

(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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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