It's very useful.
You'll like
Https-ajax.go
Package Main
Import (
"FMT"
"IO"
"Net/http"
)
Func Onajax (res http. Responsewriter, req *http. Request) {
Io. WriteString (res, "These is data from server")
}
Func Main () {
Static web
http. Handle ("/", HTTP. Fileserver (http. Dir ("Web")))
Dynamic Web
http. Handlefunc ("/ajax", Onajax)
Start server
Fmt. Println ("Server is running at localhost:8086")
ERR: = http. Listenandserve (": 8086", nil)
ERR: = http. Listenandservetls (": 8086", "Server.crt", "Server.key", nil)
If err! = Nil {
Fmt. Println ("Server failure//", err)
}
}
Small Sparrow, five Zang full
HTML:/web/ajax.html
<! DOCTYPE html>
<meta charset= "Utf-8"/>
<title>go language and Ajax examples </title>
<body>
<p><input id= "btn1" type= "button" value= "buttons"/></p>
<p><input id= "Txt1" type= "text"/></p>
<script>
Window.onload = main;
function Main () {
var obtn = document.getElementById (' btn1 ');
Obtn.onclick = OnButton1;
}
function OnButton1 () {
var xhr = new XMLHttpRequest ();
var mode = 1;
if (mode==0) {
Async
Xhr.open (' Get ', '/ajax ', true);
Xhr.send ();
Xhr.onreadystatechange = function () {
if (xhr.readystate = = 4) {
if (Xhr.status = = 200) {
var otxt = document.getElementById (' txt1 ');
Otxt.value = Xhr.responsetext;
}
}
}
}
if (mode==1) {
Sync
Xhr.open (' Get ', '/ajax ', false);
Xhr.send ();
var otxt = document.getElementById (' txt1 ');
Otxt.value = Xhr.responsetext;
}
}
</script>
</body>
Browser access
Finally:
This example is done on WIN10.
So, with the previous blog post, you should now be able to move all the features of local Windows to the Web service.
How big is that?
You don't see it! That! I'm not going to say that.
Go HTTPS Ajax