zoukankan      html  css  js  c++  java
  • go https ajax

    这个很好用啊,估计大有用武之地

    你会喜欢

    //https-ajax.go

    package main

    import (
      "fmt"
      "io"
      "net/http"
    )

    func OnAjax(res http.ResponseWriter, req *http.Request) {
      io.WriteString(res, "These are 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)
      }
    }

    麻雀小,五脏全

    //html : /web/ajax.html

    <!DOCTYPE html>

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
      <meta charset="utf-8" />
      <title>Go语言与ajax示例</title>
    </head>
    <body>
      <p><input id="btn1" type="button" value="按钮" /></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>
    </html>

    //浏览器访问

    Finally:

    这个例子是win10上做的

    所以,结合之前的博文,现在,你应该可以把本地windows的所有功能转移到web服务上了。

    这个意义,有多大?

    你看不出来!,那!就当我没说好了

  • 相关阅读:
    Linux 编程笔记(四)
    渗透测试搜索指令整理(一)
    Linux 编程笔记(三)
    Winhex数据恢复笔记(五)
    Winhex数据恢复学习笔记(四)
    Winhex数据恢复学习笔记(三)
    Linux编程学习笔记(二)
    Linux编程学习笔记(一)
    工控系统安全问题汇总(一)
    WinHex数据恢复笔记(二)
  • 原文地址:https://www.cnblogs.com/woodzcl/p/7574375.html
Copyright © 2011-2022 走看看