gpt4 book ai didi

Golang Gin 处理 AJAX 请求

转载 作者:数据小太阳 更新时间:2023-10-29 03:12:53 24 4
gpt4 key购买 nike

从前端部分ajax请求发送到golang服务器

ajax 请求示例:

    var sendAjax = function (method, url, body) {
var xmlhttp = new XMLHttpRequest();

xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState === XMLHttpRequest.DONE ) {
if (xmlhttp.status === 200) {
console.log('success');
} else if (xmlhttp.status === 400) {
alert('There was an error 400');
} else {
alert('something else other than 200 was returned');
}
}
};

xmlhttp.open(method, url, true);
xmlhttp.send(JSON.stringify({'b44': 'sdfsdfsdfs}));
};

Golang 方面

    router.POST("/save", func(context *gin.Context) {
if err := context.Request.ParseForm(); err != nil {
fmt.Println("Cannot ParseForm. Error:", err)
}

var b64FromRequest string = context.Request.FormValue("b44") //null here :(

谁能帮我解决这个问题?

最佳答案

代替 context.Request.FormValue("b44") 试试 context.PostForm("b44")

关于Golang Gin 处理 AJAX 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46342926/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com