我正在尝试在Web应用程序中使用Paho库,但是脚本src = ...标记后的所有内容均未执行。有人可以帮我吗?
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title>Temperature and Pressures</title>
<h1>Temperatures and Pressures</h1>
<script> console.log('start'); </script>
</head>
<body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/paho-mqtt/1.0.2/mqttws31.min.js" type="text/javascript">
console.log('Hello');
host = "broker.hivemq.com";
port = 8000;
clientId = "clientId-" + parseInt(Math.random() * 100);
console.log("connecting to " + host);
var client = new Paho.MQTT.Client(host, Number(port), clientId);
client.onConnectionLost = onConnectionLost;
client.onMessageArrived = onMessageArrived;
client.connect({onSuccess:onConnect});
function onConnect() {
// Once a connection has been made, make a subscription and send a message.
console.log("onConnect");
//subsribe to topics...
};
function onConnectionLost(responseObject) {
if (responseObject.errorCode !== 0)
console.log("onConnectionLost:"+responseObject.errorMessage);
};
function onMessageArrived(message) {
console.log("onMessageArrived:"+message.payloadString);
client.disconnect();
};
</script>
</body>
</html>
在控制台中记录的唯一消息是“开始”