go语言怎样把json格式的数据发给前端jquery处理

Python012

go语言怎样把json格式的数据发给前端jquery处理,第1张

这个东西跟语言没关系,你要搞清楚http的流程,在你这种情况下,go语言写的程序是作为http server,jquery作为浏览器中运行的脚本,你可以使用jquery向服务器发送ajax请求,服务器返回json数据就可以了, http.Handle("/json", fooHandler)

http.HandleFunc("/test", func(w http.ResponseWriter, r *http.Request) {

fmt.Fprintf(w, "这里写上你的json数据就行了")

})

log.Fatal(http.ListenAndServe(":8080", nil))

对于jquery就

$.get("/test/json",function(m){alert(m)})

就可以了

1.最简单的方法

public static String reverse1(String str)

{ return new StringBuffer(str).reverse().toString()

}

2.最常用的方法:

public static String reverse3(String s)

{char[] array = s.toCharArray()

String reverse = "" //注意这是空串,不是null

for (int i = array.length - 1i >= 0i--)

reverse += array[i]

return reverse

}

3.常用方法的变形:

public static String reverse2(String s)

{ int length = s.length()

String reverse = "" //注意这是空串,不是null

for (int i = 0i <lengthi++)

reverse = s.charAt(i) + reverse//在字符串前面连接, 而非常见的后面

return reverse

}