从零开始的node2 传递数组

var express=require("express");
var app=express();
var data=[{
	"aaa":"bbb"
}]
app.use(express.static("./public"));
app.get("/news",function(req,res){
	res.json(data);
});
app.listen(3000);

// app.js

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>菜鸟教程(runoob.com)</title>
</head>
<body>
    <h1 class="h1">我的第一个标题</h1>
</body>
<script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js">
</script>
<script type="text/javascript">
	$.get("/news",function(data,status){
		console.log(data);
		$(".h1").html(data[0].aaa);
	})
</script>
</html>

用ajax获取

猜你喜欢

转载自blog.csdn.net/qq_38674970/article/details/85269212