你好我有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>
答案 0 :(得分:0)
您的服务器将始终返回index.html
的内容,因此当浏览器请求时
script.js
来自它,它会获得index.html
的另一个副本。
您需要查看the URL being requested (request.url
)并为不同的网址提供不同的内容。