Calling Golang from HTML





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















I'm helping with an open source project. It's a small Go webserver running on a device containing a Raspberry Pi. I want to be able to have a user click a button on an html screen, which calls a routine in Go, which returns 2 values, a boolean and a string.



What we are wanting to do is see which network interfaces are up on the raspberry pi e.g. is the lan connection up?



To do this I really need to ping a site from each interface. This takes a few seconds for each of 3 interfaces: Lan, WiFi, and 3G.



I can do this when the page is requested and fill in an html template as the page loads, but it means waiting maybe 10 to 15 secs for the page to load, so it seems like something is broken.



So I want to be able to list each of the 3 interfaces on the page and have the user click 'test' which then calls a routine in the underlying Go webserver.



I then need to be able to display the results from the call in a couple of text areas for each interface.



What I have tried:



I have tried registering a Go function (in this case IsLANConnectionUp) using funcmap from the net/html package and calling it from the html template from a JavaScript function, like this:






  <button onclick = "getLANStatus()" class="btn btn-primary">Test</button>

<script>
function getLANStatus() {
var status = document.getElementById('status');
{{ if IsLANConnectionUp }}
status.innerHTML = "Lan is up!"
{{ else }}
status.innerHTML = "Lan is down!"
{{ end }}
}
</script>





But having the template code inside the javascript code doesn't seem to work. Also, I'd like the text output from the ping command (which my Go function getLANStatus and I don't know how to extract that data from the function call. The documentation says only one value can be returned.



Searching on StackOverflow I see this: calling Golang functions from within javascript code






$.ajax({
url: "http://www.example.com/signup",
data: {username: "whatever"} //If the request needs any data
}).done(function (data) {
// Do whatever with returned data
});





But it says things like "// Do whatever with the returned data" I'm new to web programming and so don't know how to use that code. If this is the way to go, could someone please expand on this a little?



Any help would be much appreciated.










share|improve this question























  • You're supposed to change the HTML on the page based on data. For instance like this: if (data.lanup) document.getElementById("lanstate").style.color = "green"; The exact code depends on the format of the server's reply, and how you're displaying the state of each interface.

    – Chris G
    Nov 27 '18 at 1:14











  • Hi, I understand about finding something in the DOM and changing it - once I can extract the data. Not sure what form the data will come back to me in? But firstly, how to make that call to ajax please? Do I put that code in the javascript function called from the button's onclick event?

    – davo36
    Nov 27 '18 at 2:10













  • Yes, exactly. Ideally, the GO server sends back JSON. Something like { "lanup": true, "wifiup": true, "threegup": true }. As for $.ajax, that's jQuery. It also has a simpler way: $.getJSON, but you can also use the native fetch(), that way you don't have to include jQuery in your project.

    – Chris G
    Nov 27 '18 at 2:18











  • you can simply use Ajax to do the same with ease.

    – ASHWIN RAJEEV
    Nov 27 '18 at 4:37











  • Why not run all tests at the same time, then you only wait 3 seconds, instead of 10-15.

    – Flimzy
    Nov 27 '18 at 6:37


















0















I'm helping with an open source project. It's a small Go webserver running on a device containing a Raspberry Pi. I want to be able to have a user click a button on an html screen, which calls a routine in Go, which returns 2 values, a boolean and a string.



What we are wanting to do is see which network interfaces are up on the raspberry pi e.g. is the lan connection up?



To do this I really need to ping a site from each interface. This takes a few seconds for each of 3 interfaces: Lan, WiFi, and 3G.



I can do this when the page is requested and fill in an html template as the page loads, but it means waiting maybe 10 to 15 secs for the page to load, so it seems like something is broken.



So I want to be able to list each of the 3 interfaces on the page and have the user click 'test' which then calls a routine in the underlying Go webserver.



I then need to be able to display the results from the call in a couple of text areas for each interface.



What I have tried:



I have tried registering a Go function (in this case IsLANConnectionUp) using funcmap from the net/html package and calling it from the html template from a JavaScript function, like this:






  <button onclick = "getLANStatus()" class="btn btn-primary">Test</button>

<script>
function getLANStatus() {
var status = document.getElementById('status');
{{ if IsLANConnectionUp }}
status.innerHTML = "Lan is up!"
{{ else }}
status.innerHTML = "Lan is down!"
{{ end }}
}
</script>





But having the template code inside the javascript code doesn't seem to work. Also, I'd like the text output from the ping command (which my Go function getLANStatus and I don't know how to extract that data from the function call. The documentation says only one value can be returned.



Searching on StackOverflow I see this: calling Golang functions from within javascript code






$.ajax({
url: "http://www.example.com/signup",
data: {username: "whatever"} //If the request needs any data
}).done(function (data) {
// Do whatever with returned data
});





But it says things like "// Do whatever with the returned data" I'm new to web programming and so don't know how to use that code. If this is the way to go, could someone please expand on this a little?



Any help would be much appreciated.










share|improve this question























  • You're supposed to change the HTML on the page based on data. For instance like this: if (data.lanup) document.getElementById("lanstate").style.color = "green"; The exact code depends on the format of the server's reply, and how you're displaying the state of each interface.

    – Chris G
    Nov 27 '18 at 1:14











  • Hi, I understand about finding something in the DOM and changing it - once I can extract the data. Not sure what form the data will come back to me in? But firstly, how to make that call to ajax please? Do I put that code in the javascript function called from the button's onclick event?

    – davo36
    Nov 27 '18 at 2:10













  • Yes, exactly. Ideally, the GO server sends back JSON. Something like { "lanup": true, "wifiup": true, "threegup": true }. As for $.ajax, that's jQuery. It also has a simpler way: $.getJSON, but you can also use the native fetch(), that way you don't have to include jQuery in your project.

    – Chris G
    Nov 27 '18 at 2:18











  • you can simply use Ajax to do the same with ease.

    – ASHWIN RAJEEV
    Nov 27 '18 at 4:37











  • Why not run all tests at the same time, then you only wait 3 seconds, instead of 10-15.

    – Flimzy
    Nov 27 '18 at 6:37














0












0








0








I'm helping with an open source project. It's a small Go webserver running on a device containing a Raspberry Pi. I want to be able to have a user click a button on an html screen, which calls a routine in Go, which returns 2 values, a boolean and a string.



What we are wanting to do is see which network interfaces are up on the raspberry pi e.g. is the lan connection up?



To do this I really need to ping a site from each interface. This takes a few seconds for each of 3 interfaces: Lan, WiFi, and 3G.



I can do this when the page is requested and fill in an html template as the page loads, but it means waiting maybe 10 to 15 secs for the page to load, so it seems like something is broken.



So I want to be able to list each of the 3 interfaces on the page and have the user click 'test' which then calls a routine in the underlying Go webserver.



I then need to be able to display the results from the call in a couple of text areas for each interface.



What I have tried:



I have tried registering a Go function (in this case IsLANConnectionUp) using funcmap from the net/html package and calling it from the html template from a JavaScript function, like this:






  <button onclick = "getLANStatus()" class="btn btn-primary">Test</button>

<script>
function getLANStatus() {
var status = document.getElementById('status');
{{ if IsLANConnectionUp }}
status.innerHTML = "Lan is up!"
{{ else }}
status.innerHTML = "Lan is down!"
{{ end }}
}
</script>





But having the template code inside the javascript code doesn't seem to work. Also, I'd like the text output from the ping command (which my Go function getLANStatus and I don't know how to extract that data from the function call. The documentation says only one value can be returned.



Searching on StackOverflow I see this: calling Golang functions from within javascript code






$.ajax({
url: "http://www.example.com/signup",
data: {username: "whatever"} //If the request needs any data
}).done(function (data) {
// Do whatever with returned data
});





But it says things like "// Do whatever with the returned data" I'm new to web programming and so don't know how to use that code. If this is the way to go, could someone please expand on this a little?



Any help would be much appreciated.










share|improve this question














I'm helping with an open source project. It's a small Go webserver running on a device containing a Raspberry Pi. I want to be able to have a user click a button on an html screen, which calls a routine in Go, which returns 2 values, a boolean and a string.



What we are wanting to do is see which network interfaces are up on the raspberry pi e.g. is the lan connection up?



To do this I really need to ping a site from each interface. This takes a few seconds for each of 3 interfaces: Lan, WiFi, and 3G.



I can do this when the page is requested and fill in an html template as the page loads, but it means waiting maybe 10 to 15 secs for the page to load, so it seems like something is broken.



So I want to be able to list each of the 3 interfaces on the page and have the user click 'test' which then calls a routine in the underlying Go webserver.



I then need to be able to display the results from the call in a couple of text areas for each interface.



What I have tried:



I have tried registering a Go function (in this case IsLANConnectionUp) using funcmap from the net/html package and calling it from the html template from a JavaScript function, like this:






  <button onclick = "getLANStatus()" class="btn btn-primary">Test</button>

<script>
function getLANStatus() {
var status = document.getElementById('status');
{{ if IsLANConnectionUp }}
status.innerHTML = "Lan is up!"
{{ else }}
status.innerHTML = "Lan is down!"
{{ end }}
}
</script>





But having the template code inside the javascript code doesn't seem to work. Also, I'd like the text output from the ping command (which my Go function getLANStatus and I don't know how to extract that data from the function call. The documentation says only one value can be returned.



Searching on StackOverflow I see this: calling Golang functions from within javascript code






$.ajax({
url: "http://www.example.com/signup",
data: {username: "whatever"} //If the request needs any data
}).done(function (data) {
// Do whatever with returned data
});





But it says things like "// Do whatever with the returned data" I'm new to web programming and so don't know how to use that code. If this is the way to go, could someone please expand on this a little?



Any help would be much appreciated.






  <button onclick = "getLANStatus()" class="btn btn-primary">Test</button>

<script>
function getLANStatus() {
var status = document.getElementById('status');
{{ if IsLANConnectionUp }}
status.innerHTML = "Lan is up!"
{{ else }}
status.innerHTML = "Lan is down!"
{{ end }}
}
</script>





  <button onclick = "getLANStatus()" class="btn btn-primary">Test</button>

<script>
function getLANStatus() {
var status = document.getElementById('status');
{{ if IsLANConnectionUp }}
status.innerHTML = "Lan is up!"
{{ else }}
status.innerHTML = "Lan is down!"
{{ end }}
}
</script>





$.ajax({
url: "http://www.example.com/signup",
data: {username: "whatever"} //If the request needs any data
}).done(function (data) {
// Do whatever with returned data
});





$.ajax({
url: "http://www.example.com/signup",
data: {username: "whatever"} //If the request needs any data
}).done(function (data) {
// Do whatever with returned data
});






javascript html go raspberry-pi






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 27 '18 at 1:06









davo36davo36

370411




370411













  • You're supposed to change the HTML on the page based on data. For instance like this: if (data.lanup) document.getElementById("lanstate").style.color = "green"; The exact code depends on the format of the server's reply, and how you're displaying the state of each interface.

    – Chris G
    Nov 27 '18 at 1:14











  • Hi, I understand about finding something in the DOM and changing it - once I can extract the data. Not sure what form the data will come back to me in? But firstly, how to make that call to ajax please? Do I put that code in the javascript function called from the button's onclick event?

    – davo36
    Nov 27 '18 at 2:10













  • Yes, exactly. Ideally, the GO server sends back JSON. Something like { "lanup": true, "wifiup": true, "threegup": true }. As for $.ajax, that's jQuery. It also has a simpler way: $.getJSON, but you can also use the native fetch(), that way you don't have to include jQuery in your project.

    – Chris G
    Nov 27 '18 at 2:18











  • you can simply use Ajax to do the same with ease.

    – ASHWIN RAJEEV
    Nov 27 '18 at 4:37











  • Why not run all tests at the same time, then you only wait 3 seconds, instead of 10-15.

    – Flimzy
    Nov 27 '18 at 6:37



















  • You're supposed to change the HTML on the page based on data. For instance like this: if (data.lanup) document.getElementById("lanstate").style.color = "green"; The exact code depends on the format of the server's reply, and how you're displaying the state of each interface.

    – Chris G
    Nov 27 '18 at 1:14











  • Hi, I understand about finding something in the DOM and changing it - once I can extract the data. Not sure what form the data will come back to me in? But firstly, how to make that call to ajax please? Do I put that code in the javascript function called from the button's onclick event?

    – davo36
    Nov 27 '18 at 2:10













  • Yes, exactly. Ideally, the GO server sends back JSON. Something like { "lanup": true, "wifiup": true, "threegup": true }. As for $.ajax, that's jQuery. It also has a simpler way: $.getJSON, but you can also use the native fetch(), that way you don't have to include jQuery in your project.

    – Chris G
    Nov 27 '18 at 2:18











  • you can simply use Ajax to do the same with ease.

    – ASHWIN RAJEEV
    Nov 27 '18 at 4:37











  • Why not run all tests at the same time, then you only wait 3 seconds, instead of 10-15.

    – Flimzy
    Nov 27 '18 at 6:37

















You're supposed to change the HTML on the page based on data. For instance like this: if (data.lanup) document.getElementById("lanstate").style.color = "green"; The exact code depends on the format of the server's reply, and how you're displaying the state of each interface.

– Chris G
Nov 27 '18 at 1:14





You're supposed to change the HTML on the page based on data. For instance like this: if (data.lanup) document.getElementById("lanstate").style.color = "green"; The exact code depends on the format of the server's reply, and how you're displaying the state of each interface.

– Chris G
Nov 27 '18 at 1:14













Hi, I understand about finding something in the DOM and changing it - once I can extract the data. Not sure what form the data will come back to me in? But firstly, how to make that call to ajax please? Do I put that code in the javascript function called from the button's onclick event?

– davo36
Nov 27 '18 at 2:10







Hi, I understand about finding something in the DOM and changing it - once I can extract the data. Not sure what form the data will come back to me in? But firstly, how to make that call to ajax please? Do I put that code in the javascript function called from the button's onclick event?

– davo36
Nov 27 '18 at 2:10















Yes, exactly. Ideally, the GO server sends back JSON. Something like { "lanup": true, "wifiup": true, "threegup": true }. As for $.ajax, that's jQuery. It also has a simpler way: $.getJSON, but you can also use the native fetch(), that way you don't have to include jQuery in your project.

– Chris G
Nov 27 '18 at 2:18





Yes, exactly. Ideally, the GO server sends back JSON. Something like { "lanup": true, "wifiup": true, "threegup": true }. As for $.ajax, that's jQuery. It also has a simpler way: $.getJSON, but you can also use the native fetch(), that way you don't have to include jQuery in your project.

– Chris G
Nov 27 '18 at 2:18













you can simply use Ajax to do the same with ease.

– ASHWIN RAJEEV
Nov 27 '18 at 4:37





you can simply use Ajax to do the same with ease.

– ASHWIN RAJEEV
Nov 27 '18 at 4:37













Why not run all tests at the same time, then you only wait 3 seconds, instead of 10-15.

– Flimzy
Nov 27 '18 at 6:37





Why not run all tests at the same time, then you only wait 3 seconds, instead of 10-15.

– Flimzy
Nov 27 '18 at 6:37












1 Answer
1






active

oldest

votes


















1














So couple different concepts here.



Render: On the initial request to your html that generates the Test button. Your go server will render that html 1 time and return it to your browser. It does not re-request dynamically unless you wire some stuff up to make the web page change.



Client: So when someone clicks your button, the function getLANStatus will be ran. You will want that function to do a few things





  1. Through ajax, communicate with your go server through an api that will return the status of your connections as a json object. Something like



    {
    "3g": "up",
    "lan": "down",
    "wifi": "up"
    }



  2. Second, in the done part of your ajax, you will manipulate something in the DOM in order to convey that the status of the interfaces is what it is. You could do that by finding the element, then changing the text to what is returned by the object.



As a simple first step, you can alert the payload in the function that would look like this



$.ajax({
url: "http://YOUR_GO_SERVER_IP_OR_DNS:PORT/interfaces_status.json"
}).done(function (data) {
alert(data);
console.log(data);
debugger;
});


Then if you request that with the console open in chrome, you will be able to directly play with the returned data so that you know what all it reponds to.






share|improve this answer
























  • Hi, OK, can I ask why the url is a json file? I'd need to have my Go function fill in that json file right? But how does that happen? I also don't really understand how to make that ajax call. Is it in the javascript function called by the button's onclick event?

    – davo36
    Nov 27 '18 at 2:08













  • Actually I just re-read your answer, I understand a bit more. With the lanStatus function, can I just pop that $.ajax bit into it somewhere?

    – davo36
    Nov 27 '18 at 2:14











  • You need to have your goserver serve an http api. Javascript (ajax) is going to communicate with that http api.

    – Austio
    Nov 27 '18 at 3:07











  • reddit.com/r/golang/comments/2tmllh/… good bones to get you started

    – Austio
    Nov 27 '18 at 3:09













  • This is more or less the answer...

    – davo36
    Nov 29 '18 at 18:25












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53491371%2fcalling-golang-from-html%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














So couple different concepts here.



Render: On the initial request to your html that generates the Test button. Your go server will render that html 1 time and return it to your browser. It does not re-request dynamically unless you wire some stuff up to make the web page change.



Client: So when someone clicks your button, the function getLANStatus will be ran. You will want that function to do a few things





  1. Through ajax, communicate with your go server through an api that will return the status of your connections as a json object. Something like



    {
    "3g": "up",
    "lan": "down",
    "wifi": "up"
    }



  2. Second, in the done part of your ajax, you will manipulate something in the DOM in order to convey that the status of the interfaces is what it is. You could do that by finding the element, then changing the text to what is returned by the object.



As a simple first step, you can alert the payload in the function that would look like this



$.ajax({
url: "http://YOUR_GO_SERVER_IP_OR_DNS:PORT/interfaces_status.json"
}).done(function (data) {
alert(data);
console.log(data);
debugger;
});


Then if you request that with the console open in chrome, you will be able to directly play with the returned data so that you know what all it reponds to.






share|improve this answer
























  • Hi, OK, can I ask why the url is a json file? I'd need to have my Go function fill in that json file right? But how does that happen? I also don't really understand how to make that ajax call. Is it in the javascript function called by the button's onclick event?

    – davo36
    Nov 27 '18 at 2:08













  • Actually I just re-read your answer, I understand a bit more. With the lanStatus function, can I just pop that $.ajax bit into it somewhere?

    – davo36
    Nov 27 '18 at 2:14











  • You need to have your goserver serve an http api. Javascript (ajax) is going to communicate with that http api.

    – Austio
    Nov 27 '18 at 3:07











  • reddit.com/r/golang/comments/2tmllh/… good bones to get you started

    – Austio
    Nov 27 '18 at 3:09













  • This is more or less the answer...

    – davo36
    Nov 29 '18 at 18:25
















1














So couple different concepts here.



Render: On the initial request to your html that generates the Test button. Your go server will render that html 1 time and return it to your browser. It does not re-request dynamically unless you wire some stuff up to make the web page change.



Client: So when someone clicks your button, the function getLANStatus will be ran. You will want that function to do a few things





  1. Through ajax, communicate with your go server through an api that will return the status of your connections as a json object. Something like



    {
    "3g": "up",
    "lan": "down",
    "wifi": "up"
    }



  2. Second, in the done part of your ajax, you will manipulate something in the DOM in order to convey that the status of the interfaces is what it is. You could do that by finding the element, then changing the text to what is returned by the object.



As a simple first step, you can alert the payload in the function that would look like this



$.ajax({
url: "http://YOUR_GO_SERVER_IP_OR_DNS:PORT/interfaces_status.json"
}).done(function (data) {
alert(data);
console.log(data);
debugger;
});


Then if you request that with the console open in chrome, you will be able to directly play with the returned data so that you know what all it reponds to.






share|improve this answer
























  • Hi, OK, can I ask why the url is a json file? I'd need to have my Go function fill in that json file right? But how does that happen? I also don't really understand how to make that ajax call. Is it in the javascript function called by the button's onclick event?

    – davo36
    Nov 27 '18 at 2:08













  • Actually I just re-read your answer, I understand a bit more. With the lanStatus function, can I just pop that $.ajax bit into it somewhere?

    – davo36
    Nov 27 '18 at 2:14











  • You need to have your goserver serve an http api. Javascript (ajax) is going to communicate with that http api.

    – Austio
    Nov 27 '18 at 3:07











  • reddit.com/r/golang/comments/2tmllh/… good bones to get you started

    – Austio
    Nov 27 '18 at 3:09













  • This is more or less the answer...

    – davo36
    Nov 29 '18 at 18:25














1












1








1







So couple different concepts here.



Render: On the initial request to your html that generates the Test button. Your go server will render that html 1 time and return it to your browser. It does not re-request dynamically unless you wire some stuff up to make the web page change.



Client: So when someone clicks your button, the function getLANStatus will be ran. You will want that function to do a few things





  1. Through ajax, communicate with your go server through an api that will return the status of your connections as a json object. Something like



    {
    "3g": "up",
    "lan": "down",
    "wifi": "up"
    }



  2. Second, in the done part of your ajax, you will manipulate something in the DOM in order to convey that the status of the interfaces is what it is. You could do that by finding the element, then changing the text to what is returned by the object.



As a simple first step, you can alert the payload in the function that would look like this



$.ajax({
url: "http://YOUR_GO_SERVER_IP_OR_DNS:PORT/interfaces_status.json"
}).done(function (data) {
alert(data);
console.log(data);
debugger;
});


Then if you request that with the console open in chrome, you will be able to directly play with the returned data so that you know what all it reponds to.






share|improve this answer













So couple different concepts here.



Render: On the initial request to your html that generates the Test button. Your go server will render that html 1 time and return it to your browser. It does not re-request dynamically unless you wire some stuff up to make the web page change.



Client: So when someone clicks your button, the function getLANStatus will be ran. You will want that function to do a few things





  1. Through ajax, communicate with your go server through an api that will return the status of your connections as a json object. Something like



    {
    "3g": "up",
    "lan": "down",
    "wifi": "up"
    }



  2. Second, in the done part of your ajax, you will manipulate something in the DOM in order to convey that the status of the interfaces is what it is. You could do that by finding the element, then changing the text to what is returned by the object.



As a simple first step, you can alert the payload in the function that would look like this



$.ajax({
url: "http://YOUR_GO_SERVER_IP_OR_DNS:PORT/interfaces_status.json"
}).done(function (data) {
alert(data);
console.log(data);
debugger;
});


Then if you request that with the console open in chrome, you will be able to directly play with the returned data so that you know what all it reponds to.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 27 '18 at 1:21









AustioAustio

4,6351229




4,6351229













  • Hi, OK, can I ask why the url is a json file? I'd need to have my Go function fill in that json file right? But how does that happen? I also don't really understand how to make that ajax call. Is it in the javascript function called by the button's onclick event?

    – davo36
    Nov 27 '18 at 2:08













  • Actually I just re-read your answer, I understand a bit more. With the lanStatus function, can I just pop that $.ajax bit into it somewhere?

    – davo36
    Nov 27 '18 at 2:14











  • You need to have your goserver serve an http api. Javascript (ajax) is going to communicate with that http api.

    – Austio
    Nov 27 '18 at 3:07











  • reddit.com/r/golang/comments/2tmllh/… good bones to get you started

    – Austio
    Nov 27 '18 at 3:09













  • This is more or less the answer...

    – davo36
    Nov 29 '18 at 18:25



















  • Hi, OK, can I ask why the url is a json file? I'd need to have my Go function fill in that json file right? But how does that happen? I also don't really understand how to make that ajax call. Is it in the javascript function called by the button's onclick event?

    – davo36
    Nov 27 '18 at 2:08













  • Actually I just re-read your answer, I understand a bit more. With the lanStatus function, can I just pop that $.ajax bit into it somewhere?

    – davo36
    Nov 27 '18 at 2:14











  • You need to have your goserver serve an http api. Javascript (ajax) is going to communicate with that http api.

    – Austio
    Nov 27 '18 at 3:07











  • reddit.com/r/golang/comments/2tmllh/… good bones to get you started

    – Austio
    Nov 27 '18 at 3:09













  • This is more or less the answer...

    – davo36
    Nov 29 '18 at 18:25

















Hi, OK, can I ask why the url is a json file? I'd need to have my Go function fill in that json file right? But how does that happen? I also don't really understand how to make that ajax call. Is it in the javascript function called by the button's onclick event?

– davo36
Nov 27 '18 at 2:08







Hi, OK, can I ask why the url is a json file? I'd need to have my Go function fill in that json file right? But how does that happen? I also don't really understand how to make that ajax call. Is it in the javascript function called by the button's onclick event?

– davo36
Nov 27 '18 at 2:08















Actually I just re-read your answer, I understand a bit more. With the lanStatus function, can I just pop that $.ajax bit into it somewhere?

– davo36
Nov 27 '18 at 2:14





Actually I just re-read your answer, I understand a bit more. With the lanStatus function, can I just pop that $.ajax bit into it somewhere?

– davo36
Nov 27 '18 at 2:14













You need to have your goserver serve an http api. Javascript (ajax) is going to communicate with that http api.

– Austio
Nov 27 '18 at 3:07





You need to have your goserver serve an http api. Javascript (ajax) is going to communicate with that http api.

– Austio
Nov 27 '18 at 3:07













reddit.com/r/golang/comments/2tmllh/… good bones to get you started

– Austio
Nov 27 '18 at 3:09







reddit.com/r/golang/comments/2tmllh/… good bones to get you started

– Austio
Nov 27 '18 at 3:09















This is more or less the answer...

– davo36
Nov 29 '18 at 18:25





This is more or less the answer...

– davo36
Nov 29 '18 at 18:25




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53491371%2fcalling-golang-from-html%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Wiesbaden

Marschland

Dieringhausen