I am making web application using Golang with GIN. I can bring json data when Ajax type is GET
, but When Ajax type is POST
, I don't no how to send json data to GO server. I used method PostForm()
and GetPostForm()
, But It is not working. Plz help me.
Here is my code:
join.js
var json_memberInfo = `{
"id": "`+id+`",
"password": "`+password+`",
"name": "`+name+`",
"birthday": "`+birthday+`",
"tel": "`+tel+`",
"email": "`+email+`"
}`;
var parse_memberInfo = JSON.parse(json_memberInfo);
alert(json_memberInfo);
$.ajax({
url: "/join",
type: "POST",
data: parse_memberInfo,
contentType: "application/json",
success: function(result) {
if (result) {
//alert("회원가입이 완료되었습니다!");
}
else {
//alert("에러가 발생하였습니다. 잠시 후에 다시 시도하여 주세요.");
}
}
})
main.go
router.POST("/join", func(c *gin.Context) {
id := c.PostForm("id")
password := c.PostForm("password")
name := c.PostForm("name")
birthday := c.PostForm("birthday")
tel := c.PostForm("tel")
email := c.PostForm("email")
fmt.Println(id + " " + password + " " + name + " " + birthday + " " + tel + " " + email)
})