简体   繁体   English

节点js要求浏览器重新加载页面

[英]node js asking browser to reload the page

I want to reload the page after some validations placed at the server side fails.. i have already tried with res.redirect res.location and location.reload() . 我想在服务器端进行的某些验证失败后重新加载页面。.我已经尝试过使用res.redirect res.locationlocation.reload()

I need to place the reloading logic on the server side in nodeJS. 我需要将重载逻辑放在nodeJS的服务器端。

So whenever there is a request from client side this validation gets triggered and if the validation fails i am destroying the window user object but i am unable to reload the page...it's stays on the same same and then all services starts failing..because of user object check now.. 因此,每当有来自客户端的请求时,都会触发此验证,如果验证失败,我将销毁窗口用户对象,但无法重新加载页面...它保持不变,然后所有服务都开始失败。因为现在检查用户对象。

If you do an ajax call you need to reload in the client side browser code based on http response. 如果执行ajax调用,则需要基于http响应重新加载客户端浏览器代码。 if it's a form post you can render whatever html you want back to the client. 如果是表单发布,则可以将所需的任何html呈现回客户端。

A way to build this in your ajax framework would be to: In serverside you could redirect and then clientside, have the code that looks like this (warning this is just psuedo code): 在ajax框架中构建此代码的方法是:在服务器端,您可以重定向,然后在客户端,获得如下所示的代码(警告这只是伪代码):

if(response.httpStatusCode == 301 or 302)
 window.location(response.headers.location)

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

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