res对象json,redirect
2024-09-08 04:05:03
1.res.json()
var express=require('express');
var app=express(); app.get('/',function(req,res){
//返回json,
res.json({name:'jim',age:'100'});
}) app.listen(9090,function(){
console.log('http://localhost:9090');
})
res.json()将参数转化为json对象,请求方式和res.send差不多
2.res.redirect([status,] path)
重定向到从指定的URL到的另一个URL ,具有指定的
status
与HTTP状态代码对应的正整数。如果未指定,则status
默认为“302”找到“。
res.redirect('/foo/bar');
res.redirect('http://example.com');
res.redirect(301, 'http://example.com');
res.redirect('../login');
重定向可以是用于重定向到其他站点的完全限定URL:
res.redirect('http://google.com');
重定向可以相对于主机名的根目录。例如,如果应用程序已启用http://example.com/admin/post/new
,则以下内容将重定向到URL http://example.com/admin
:
res.redirect('/admin');
重定向可以相对于当前URL。例如,从http://example.com/blog/admin/
(注意尾部斜杠),以下将重定向到URL http://example.com/blog/admin/post/new
。
res.redirect('post/new');
重定向到post/new
的http://example.com/blog/admin
(没有尾随斜线),会重定向到http://example.com/blog/post/new
。
如果您发现上述行为令人困惑,请将路径段视为目录(带有斜杠)和文件,它将开始有意义。
路径相对重定向也是可能的。如果您在 http://example.com/admin/post/new
,以下将重定向到 http://example.com/admin/post
:
res.redirect('..');
一个back
重定向请求重定向回引荐,默认为/
引荐丢失时。
res.redirect('back');
最新文章
- [spring源码学习]二、IOC源码——配置文件读取
- python基础篇
- Pixar Shorts 皮克斯动画短片全集
- PHP5的对象复制
- 简单JSONP跨域请求
- 初识Mongodb之[CURD]-PHP版
- XMPP协议的基本理解
- [HNOI2002]彩票
- 仿照selalchemy实现简单的mongo查询
- git 的 origin 的含义
- hadoop集群运行jps命令以后Datanode节点未启动的解决办法
- Code first 数据迁移
- vue cli搭建的vue项目 不小心开了eslint 一直报黄色的警告
- matlib实现logistic回归算法(序一)
- stm8 时钟输出引脚
- springboot+sqlite+maven+mybatis
- 临时文件夹迁移 temp位置移动
- java对象流与序列化
- 20155203 2016-2017-2 《Java程序设计》第1周学习总结
- USACO 3.3.1 Riding the Fences 骑马修栅栏(欧拉回路)