Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 节点js调用html并从html中激活“filename”.js_Javascript_Html_Node.js - Fatal编程技术网

Javascript 节点js调用html并从html中激活“filename”.js

Javascript 节点js调用html并从html中激活“filename”.js,javascript,html,node.js,Javascript,Html,Node.js,你好,我有html,我叫它index.html,在里面他激活了someScript.js,我叫它script.js,现在我想从节点js调用index.html,我叫它server.js,但当我调用index.html时,他没有激活script.js。他只给我看html格式的内容 //only displaying the "blaaaa" that in the index.html //this is the **script.js** that i talked about {

你好,我有html,我叫它index.html,在里面他激活了someScript.js,我叫它script.js,现在我想从节点js调用index.html,我叫它server.js,但当我调用index.html时,他没有激活script.js。他只给我看html格式的内容

//only displaying the "blaaaa" that in the index.html


//this is the **script.js** that i talked about
{
    // here i read my index.html
    var http = require('http');
    var fs = require('fs');
    var content;
    // First I want to read the file
    fs.readFile('./index.html ', function read(err, html) {
        if (err) 
{
          throw err;
        }
        content = html;


    http.createServer(function(request,response){
    response.writeHead(200,{"Content-Type": "text/html"});
    response.write(html);
    response.end();

    }).listen(8081);

    console.log("listening on oprt 8081");


    });
}  

    //if i activate directly the index.html its working but because i tried to activate it from the script it doesn't  work
    **index.html**

    <html>
        <head>
            <script src="http://code.jquery.com/jquery-2.1.0.min.js"></script>  
            <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
            <script src="script.js"></script>
            <script>
            </script>
        </head>
        <body>
            <div id="blankdiv"> blaaaa </div>


        </body>
    </html>

您的服务器将始终返回index.html的内容,因此当浏览器请求 从中获取index.html的另一个副本

您需要查看并为不同的URL提供不同的内容