如何将错误消息从后端(sails.js)传递到前端 [英] how to pass the error messages from back end(sails.js) to front end

查看:39
本文介绍了如何将错误消息从后端(sails.js)传递到前端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我必须将任何消息/错误传递给前端,在sails.js 中.

If i have to pass any message/error to front end , in sails.js.

我们可以使用以下其中一种.

Either we can use one of the following below.

  1. res.view({error : error}) 
  2. res.view("/otherpageurl", {error : error})
  3. res.redirect("/otherpageurl?error="+error)

在某些情况下,如果我在页面 A 中,如果发生任何错误,我只想重定向到另一个页面,并将错误消息传递给前端.而在某些情况下,我只想在同一页面中显示错误.

In some cases , If iam in page A , if any error occurs , i just want to redirect to another page with the error message passed to frontend.whereas in some cases , i just want to show the error in same page.

还有其他可能将错误消息传递给前端吗?

Is there any other possiblity of passing error messages to frontend?

请帮忙.非常感谢.

推荐答案

技术上您可以为此使用 flash 中间件...

Technically you can use the flash middleware for this...

所以你会这样做:

req.flash('error', 'Error Message!')
res.redirect('/otherpageurl');

然后在您看来:

<%- req.flash('error') %>

这篇关于如何将错误消息从后端(sails.js)传递到前端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆