调包侠 之 webworker

参考文献

晚上回家,实装一下。。。

MAMP 后台服务器的搭建

客户端方面:

00_webworker_demo.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script type="text/javascript">
        var worker = new Worker("li.js");
        worker.postMessage("hello server!!! webworker");

        worker.onmessage = function(res){
            console.log(res.data);
        }
    </script>
</head>
<body>
    
</body>
</html>

js 服务器方面

li.js

this.onmessage = function(res){
    var data = res.data;
    var lastData = data.toUpperCase();
    this.postMessage(lastData);
}

在浏览器上访问

http://localhost/00_webworker_demo.html

浏览器 控制台 可输出

HELLO SERVER!!! WEBWORKER

发布了42 篇原创文章 · 获赞 1 · 访问量 5375

猜你喜欢

转载自blog.csdn.net/MENGCHIXIANZI/article/details/105215942
今日推荐