【问题标题】:How to get element's status of response body如何获取响应体的元素状态
【发布时间】:2020-05-04 10:05:22
【问题描述】:

有一个与 expressJS 相关的表单。当我按下提交按钮时,将输入数据(图像方向)形成一个路径,我通过 router.post() 函数得到它。

当我发送错误的图像方向时,图像状态的响应是404。

问题是如何获得此状态。我想把它放在一个变量中。

表格代码:

extends ../layouts/main-layout.pug
block content
    form(action='/admin/add-product', method='POST')
        .row
            .input-field.col.s6
                input#name.validate(name ='name',type='text', placeholder='Please Enter A Product Name')
            .input-field.col.s6
                input#name.validate(name='image',type='text', placeholder='Please Enter A Product Image')
            .input-field.col.s6
                input#name.validate(name='state',type='text', placeholder='Please Enter A Product State')
            .input-field.col.s6
                input#name.validate(name='price',type='text', placeholder='Please Enter A Product Price')
            .input-field.col.s12
                button.btn.waves-effect.waves-light(type='submit', name='submit')| Submit

router.get 代码:

module.exports.postAddProduct = (req, res) => {
    console.log(req.body.name);
    res.redirect('/');
};

【问题讨论】:

  • 贴代码!!!
  • 我已经发布了

标签: javascript node.js express ejs


【解决方案1】:

控制台响应并像console.log(res.status);一样访问它

【讨论】:

  • 我已经试过了。但它也给出了 200 个代码。我想像上图一样获取图像的状态码。
猜你喜欢
  • 2015-04-29
  • 2011-10-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-07-17
  • 2021-11-07
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多