简体   繁体   中英

Go - How to receive json data which ajax type is DELETE using gin

I'm making web application. But I conflict big problem. In back-end, I made function for DELETE.

Here is DELETE function :

router.DELETE("/rsv/delete", func(c *gin.Context) {
    //how to receive json data?
})

And I send json data by Ajax.

Here is Ajax function :

$.ajax({
    url: "/rsv/delete",
    type: "DELETE",
    data: parse_delete,
    contentType: "application/json",
    success: function(result) {
        if (result) {
            alert("삭제가 완료되었습니다!");
            location.href = "/member_index";
        }

        else {
            alert("Error");
        }
    }
})

Please Help me.

You may try BindJson method of gin.Context .

var json SomeJsonStruct
if c.BindJSON(&json) == nil {
    //...
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM