zoukankan      html  css  js  c++  java
  • res对象json,redirect

     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 ,具有指定的statusHTTP状态代码对应的正整数如果未指定,则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/newhttp://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');
     
  • 相关阅读:
    navicat 连接Oracle 报错 ORA-12514 TNS:listener does not currently know of service requested in connect descriptor
    centos 安装配置 redis
    ubuntu安装keras
    VB类似的InputBox为MFC
    WPF颜色选择器
    窗口样式
    IP地址、端口号、子网掩码提交表单库
    添加自定义对话框,您的应用程序
    在c#中使用异步等待构建响应式UI
    一个通用对话框
  • 原文地址:https://www.cnblogs.com/ellen-mylife/p/11072085.html
Copyright © 2011-2022 走看看