[英]JSON cannot unmarshal object into GO value of type string
Writing Golang app using github.com/zserge/lorca
package. 使用
github.com/zserge/lorca
包编写Golang应用程序。 This binds golang funcs to Javascript. 这会将golang函数绑定到Javascript。 I have HTML with text input and submit button which should pass the text input as an arg into the Javascript binding.
我有带有文本输入和提交按钮的HTML,该按钮应将文本输入作为arg传递到Javascript绑定中。 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. JSBINDFUNC
采用golang类型的string
作为输入。 When I hit submit, it should be passing the text entered for MACADD
as an arg into the JSBINDFUNC
func. 当我点击提交时,它应该将为
MACADD
输入的文本作为一个参数传递给JSBINDFUNC
函数。
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
. 需要这个
object
成为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()
}
The issue is with your javascript. 问题出在您的JavaScript。 Update your onclick attribute like so:
像这样更新您的onclick属性:
<input type="submit" value="Submit" onclick="JSBINDFUNC(MACADD.value)">
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.