如何从gin中的前端获取数据? [英] How get DATA from frontend in gin?

查看:83
本文介绍了如何从gin中的前端获取数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我感到遗憾的是,我一直无法弄清楚如何从Gin框架的前端获取数据.在Django中,我得到了数据,所以:

To my shame, I have not been able to figure out how to get data from the frontend in Gin framework. In Django I get data So:

user=request.data.get('user')
print(user)

一切都是简单易懂的.我应该如何在杜松子酒中做到这一点?

Everything is simple and understandable as day. How should I do it in gin?

user := c.Query("user")
user := c.Param("user")
user := c.Params.ByName("user")
user := c.PostForm("user")
println(user)//emptiness....

推荐答案

服务器GIN无法处理来自axios的常规默认应用程序/json请求!!!什么???请求应以application/x-www-form-urlencoded的形式发送.我在Vue项目中的决定:使用带有选项的vue-resource代替axios(axios.post => this.$ http.post)Vue.http.options.emulateJSON = true;在main.js中

Server GIN can't handle routine default application/json requests from axios!!! What??? Requests should be sent as application/x-www-form-urlencoded. My decision in Vue project: Use vue-resource instead axios (axios.post=>this.$http.post) with option Vue.http.options.emulateJSON = true; in main.js

这篇关于如何从gin中的前端获取数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆