zoukankan      html  css  js  c++  java
  • nodejs不同浏览器跳转问题

    前提:配置好简单的nodejs和bootstrap的服务,让用户可以通过localhost:8001和localhost:8001/index.html都可以访问

     1             fs.readFile("."+request.url,'utf-8',function(err,data)
     2             {
     3                 if(err)
     4                 {
     5                     throw err;
     6                 }
     7                 response.writeHead(200,{"Content-Type":{
     8                     ".html":"text/type",
     9                     ".css":"text/css",
    10                     ".js" :"application/javascript"
    11                 }
    12                 });
    13                 response.write(data);
    14                 response.end();
    15             })
    16         

    火狐:两个入口都可以访问,样式也正常加载了。

    ie:localhost:8001/index.html可以正常访问,localhost:8001是下载index.html页面

    chrome:两个入口都可以访问,但样式加载不了

    解决办法:

     switch (ext)
        {
            case ".css":
            case ".js":
                fs.readFile("."+request.url,'utf-8',function(err,data){
                    if(err)
                    {
                        throw err;
                    }
                    response.writeHead(200,{"Content-Type":{
                        ".css":"text/css",
                        ".js" :"application/javascript"
                    }[ext]
                    });
                    response.write(data);
                    response.end();
                })
                break;
            default :
              fs.readFile("./index.html","utf-8",function(err,data)
                    {
                        if(err) throw err;
                        response.writeHead(200,{"Content-Type":"text/html"});
                        response.write(data);
                        response.end();
                    });
    }
      
  • 相关阅读:
    NSClassFromString,NSSelectorFromString,isKingOfClass
    [ios2]10大iOS开发者最喜爱的类库
    [ios2]iphone编程中使用封装的NSLog来打印调试信息 【转】
    [ios2]蓝牙通信【转】
    [ios] Xcode使用设置相关-快捷键【转】
    iOS图片设置圆角
    iOS 时间戳转时间
    iOS 时间转时间戳
    iOS loading等待图
    iOS简便写法
  • 原文地址:https://www.cnblogs.com/hellowoody/p/3961956.html
Copyright © 2011-2022 走看看