drwdvftp423507 2019-03-27 17:54
浏览 71
已采纳

JSON无法将对象解组为字符串类型的GO值

Writing Golang app using github.com/zserge/lorca package. This binds golang funcs to Javascript. I have HTML with text input and submit button which should pass the text input as an arg into the Javascript binding. It looks as follows:

<input type="text" name="MACADD" style="height:20px; width:210px">
<input type="submit" value="submit" onclick="JSBINDFUNC(MACADD)">

The JSBINDFUNC takes golang type string for input. When I hit submit, it should be passing the text entered for MACADD as an arg into the JSBINDFUNC func.

However, I'm coming back with the err

exception":{"type":"string","value":"json: cannot unmarshal object into Go value of type string"}

Needing this object to become golang string.

More complete snip:

package main

import (
    "fmt"
    "log"
    "net/url"

    "github.com/zserge/lorca"
)

func main() {
    ui, err := lorca.New("data:text/html,"+url.PathEscape(`
        <html>
                <form action="/action_page.php">
                    MAC Address:<br>
                    <input type="text" name="MACADD" style="height:20px; width:210px">
                    <input type="submit" value="Submit" onclick="JSBINDFUNC(MACADD)">
                </form> 
            </body>
        </html>
        `), "", 480, 320)
    if err != nil {
        log.Fatal(err)
    }
    //ui.Bind implemented @ https://github.com/zserge/lorca/blob/master/ui.go#L110
    ui.Bind("JSBINDFUNC", func(MAC string) {
        fmt.Println(MAC)
        return
    })
    defer ui.Close()
    <-ui.Done()
}

  • 写回答

1条回答 默认 最新

  • dporb84480 2019-03-27 20:04
    关注

    The issue is with your javascript. Update your onclick attribute like so:

    <input type="submit" value="Submit" onclick="JSBINDFUNC(MACADD.value)">
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?