jsonp:通过请求script资源
html代码:
<body>
<div> hello world</div>
</body>
<style></style>
<script>
function hello() {
document.querySelector("div").style.backgroundColor = "green"
}
</script>
<script src="http://localhost:80?callback=hello"></script>
node代码:
var http = require("http");
var server = http.createServer(function (req, res) {
console.log("有人访问");
res.write("hello();");
res.end();
});
server.listen(80);
console.log("server启动了 ");