Hello,
for quite a while now, Iam looking forward to manage or at least show “databases” (stored arrays of objects) in a webinterface so it’s easier for me to see some data more clear. Unfortunately nobody could really explain me how to do so and I also couldn’t figure it out by myself.
All I want to do is send data from the webpage to the script, and request data of the script from the webpage.
Here is what I want to do in code, I hope its a bit more clear and maybe you can help me out
Am I on the right track?
If someone has the time to explain this to me, I would be excessively happy!
Greetings Everlike
for quite a while now, Iam looking forward to manage or at least show “databases” (stored arrays of objects) in a webinterface so it’s easier for me to see some data more clear. Unfortunately nobody could really explain me how to do so and I also couldn’t figure it out by myself.
All I want to do is send data from the webpage to the script, and request data of the script from the webpage.
Here is what I want to do in code, I hope its a bit more clear and maybe you can help me out
JavaScript:
registerPlugin({
name: 'script <-> webpage communicator',
version: '0.0.1',
description: 'Script, trying to communicate with a webpage.',
author: 'Everlike <[email protected]>',
enableWeb: true,
requiredModules: ["http"],
vars: [
]
}, function (sinusbot, config) {
var engine = require ('engine');
var backend = require ('backend');
var event = require ('event');
var store = require ('store');
var http = require ('http');
event.on('api:caseOne', ev => {
engine.log(/*received data from .html file in this case "Aloah"*/);
});
event.on('api:caseTwo', ev => {
var infoTheWebpageWant = "Hey Website, its me, the script";
//send "Hey Website, its me, the script" to the .html file when requested
});
});
HTML:
<!DOCTYPE html>
<html>
<head>
<title>A Page to communicate with a sinusbot script!</title>
</head>
<body>
<b>Click the following button to send a variable to the script<b>
<button onclick="sendDataToScript()">Click me</button>
<br>
<b>Click the following button to request some data from the script<b>
<button onclick="requestDataFromScript()">Click me</button>
<br>
<script>
function sendDataToScript() {
var word = "aloah";
//send the variable "word" to the script. communicate with script event: "api:caseOne"
};
function requestDataFromScript() {
var someInfo;
//reqest a var(string) from the script and save it to the "someInfo" variable on the website by communicating with the "api:caseTwo" event.
}
</script>
</body>
</html>
Am I on the right track?
If someone has the time to explain this to me, I would be excessively happy!
Greetings Everlike
Last edited: