我正在尝试在chrome上创建推送通知系统.我有一个从mysql获取数据并回显JSON的php,现在我想调用一个函数getJsonCode(),它在推送通知到达时被激活并读取JSON数据.
在我的服务工作者中,我创建了标准函数.问题是,当我使用XMLHttpRequest创建getJsonCode时,它告诉我它没有定义
self.addEventListener('install', function(event) {
self.skipWaiting();
console.log('Installed', event);
});
self.addEventListener('activate', function(event) {
console.log('Activated', event);
});
self.addEventListener('push', function(event) {
console.log('Push message', event);
getJsonCode();
);
})
getJsonCode() {
codeRequest= new XMLHttpRequest();
codeRequest.open('get', 'myfileWithJson.php', true);
codeRequest.send();
dataJSON = codeRequest.responseText;
console.log('rispostaJSON');
}
Run Code Online (Sandbox Code Playgroud)
是否可以在服务工作者中调用这样的外部文件,或者是否存在某些限制?因为我不知道为什么这不起作用
php json push-notification google-cloud-messaging service-worker
我有一个在本地服务器上运行的脚本,该脚本可获取一个php文件(也在本地服务器上)。如果我编写要获取的url作为相对路径,则文件不会出现问题,但是,如果添加127.0.0.1/mypath/myFile,则会出现403错误。
function localServerCall() {
var urlLocalServer = '127.0.0.1:8000/mypath/myfile.php';
//var urlLocalServer = 'myfile.php'; //THIS WORKS!
fetch(urlLocalServer).then(function(response) {
console.log(response.json);
return response.json();
}).then(function(data) {
console.log(data)
}).catch(function(err) {
console.log ('ERROR LOCALSERVER', err);
})
}
Run Code Online (Sandbox Code Playgroud)
我想知道绝对/相对URL与fetch的使用是否存在某些限制,或者此问题是否可能是由于其他原因引起的。
我正在尝试在树莓派paho的MQTT Broker上发布消息。我已经使用Visual Studio 2015(在Windows 10上)构建了一个“应用程序”,并且正在使用波纹模拟器对其进行测试,但是我总是会收到此错误
AMQJS0011E未连接无效状态。
我还尝试导出文件,并在Linux系统上使用firefox将其打开为常规网页,但出现了同样的错误,因此我认为与Windows无关。
通过按钮触发的函数是playCanzone()
function playCanzone() {
console.log("play premuto");
mqttHost = '192.168.9.184';
topic = 'testTopic';
client = new Paho.MQTT.Client(mqttHost, 8080, "myclientid_" + parseInt(Math.random() * 100, 10));
onConnect();//publish('mEssaggio', 'testtopic/bar', 2);
}
// set callback handlers
client.onConnectionLost = onConnectionLost;
client.onMessageArrived = onMessageArrived;
// connect the client
client.connect({ onSuccess: onConnect });
// called when the client connects
function onConnect() {
// Once a connection has been made, make a subscription and send a message.
console.log("onConnect");
client.subscribe(topic);
message = new …
Run Code Online (Sandbox Code Playgroud)