douchi0471 2018-09-15 15:13
浏览 36

在golang中使用javascript响应网页

I have a webpage with login and password forms If login or password are wrong how could I response with javascript alert() or console.log() functions in golang

<body>
    <!-- LOGIN FORM -->
    <div class="login-page">
        <div class="form">
          <form class="login-form"action="/login" method="POST">
            <input type="text"   name="username"   placeholder="username"/>
            <input type="password" name="password" placeholder="password"/>
            <button type="submit" id="send" value="Login">Login</button>
          </form>
        </div>
      </div>
</body>

GOLANG

func (c *AuthenticationControllers) AdminLogin() http.HandlerFunc {
    return func(w http.ResponseWriter, r *http.Request) {

        switch r.Method {
        case "GET":
            http.ServeFile(w, r, "C:/Projects/Go/src/github.com/AlifElectronicQueue/web/template/login.html")
        case "POST":

            //********AUTHENTICATION PROCESS*********//
            if loginAns {
                //Some code
                http.Redirect(w, r, "/admin/applications", 302)

            }  else {
                http.Redirect(w, r, "/login", 302)
                http.Error(w, http.StatusText(http.StatusForbidden), http.StatusForbidden)
            } 
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序
    • ¥15 onvif+openssl,vs2022编译openssl64
    • ¥15 iOS 自定义输入法-第三方输入法
    • ¥15 很想要一个很好的答案或提示
    • ¥15 扫描项目中发现AndroidOS.Agent、Android/SmsThief.LI!tr
    • ¥15 怀疑手机被监控,请问怎么解决和防止
    • ¥15 Qt下使用tcp获取数据的详细操作
    • ¥15 idea右下角设置编码是灰色的
    • ¥15 全志H618ROM新增分区
    • ¥15 在grasshopper里DrawViewportWires更改预览后,禁用电池仍然显示