nodejs的ajax渲染http+fs核心模块

本文介绍了一个使用Node.js创建的简易服务器,通过监听3020端口,根据不同的URL请求,读取并返回本地文件,包括HTML页面、CSS样式、JavaScript脚本及图片资源。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

var http=require(‘http’)
var fs=require(‘fs’)
http.createServer(function(req,res){
if(req.url==’/’){
fs.readFile(’…/new_file.html’,function(err,data){

		res.end(data)
	})
}else if(req.url=='/btostro'){
	fs.readFile('../bootstrap-3.3.7-dist/css/bootstrap.css',function(err,data){
		 
		res.end(data)
	})
}else if(req.url=='/jquery'){
	fs.readFile('jquery-3.2.1.js',function(err,data){
		 
		res.end(data)
	})
}else if(req.url=='/bootstrapjs'){
	fs.readFile('../bootstrap-3.3.7-dist/js/bootstrap.js',function(err,data){
		 
		res.end(data)
	})
}else if(req.url=='/one'){
	fs.readFile('../css/one.css',function(err,data){
		 
		res.end(data)
	})
}else if(req.url=='/manwei'){
	fs.readFile('../images/1_03.gif',function(err,data){
		 
		res.end(data)
	})
}else if(req.url=='/shouye'){
	fs.readFile('shouye.json',function(err,data){
		 
		res.end(data)
	})
}else if(req.url=='/images/1_06.gif'){
	fs.readFile('../images/1_06.gif',function(err,data){
		 
		res.end(data)
	})
}else if(req.url=='/images/1_10.gif'){
	fs.readFile('../images/1_10.gif',function(err,data){
		 
		res.end(data)
	})
}else if(req.url=='/images/1_14.gif'){
	fs.readFile('../images/1_14.gif',function(err,data){
		 
		res.end(data)
	})
}else if(req.url=='/images/1_16.gif'){
	fs.readFile('../images/1_16.gif',function(err,data){
		 
		res.end(data)
	})
}else if(req.url=='/renwu'){
	fs.readFile('renwu.json',function(err,data){
		 
		res.end(data)
	})
}else if(req.url=='/images/2_03.gif'){
	fs.readFile('../images/2_03.gif',function(err,data){
		 
		res.end(data)
	})
}else if(req.url=='/images/2_05.gif'){
	fs.readFile('../images/2_05.gif',function(err,data){
		 
		res.end(data)
	})
}else if(req.url=='/images/2_07.gif'){
	fs.readFile('../images/2_07.gif',function(err,data){
		 
		res.end(data)
	})
}else if(req.url=='/images/2_09.gif'){
	fs.readFile('../images/2_09.gif',function(err,data){
		 
		res.end(data)
	})
}else if(req.url=='/images/2_15.gif'){
	fs.readFile('../images/2_15.gif',function(err,data){
		 
		res.end(data)
	})
}else if(req.url=='/images/2_16.gif'){
	fs.readFile('../images/2_16.gif',function(err,data){
		 
		res.end(data)
	})
}else if(req.url=='/images/2_18.gif'){
	fs.readFile('../images/2_18.gif',function(err,data){
		 
		res.end(data)
	})
}else if(req.url=='/images/2_20.gif'){
	fs.readFile('../images/2_20.gif',function(err,data){
		 
		res.end(data)
	})
}

}).listen(3020)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值