1、引入无dom的jquery
importScripts("js/jquery.nodom.js");
下载地址:jquery.nodom.js
下载地址:jquery.nodom.js
2、这时候就可以直接用ajax啦
function changeMode(){ var endoding= "admin:password"; //var encoding = $.base64.encode(code); $.ajax({ type: "GET", // url: "http://{{ip}}/ccpiot/api/assignments/{{token}}/measurements?page=1&pageSize=1", url: "http://192.168.20.201:8089/ccpiot/api/assignments/ec1a83f6_d2a9_4d45_b68b_1f41070441ad/measurements?page=1&pageSize=1", async: false, timeout: 1000, success: function (datab) { self.postMessage(num)//向主线程发消息 }, error: function (data) { console.log(data) }, beforeSend: function (xhr) { xhr.setRequestHeader("Authorization", " Basic " + encoding); xhr.setRequestHeader("X-SiteWhere-Tenant", "lab517"); } }) } changeMode(); setInterval(function (){ changeMode(); },20000);