New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
redirect is not success #3903
Comments
Hello my friend, do you want to redirect the request parameters to the new html? If so, please refer to the code example below: package main
import (
"fmt"
"net/http"
"github.com/gin-gonic/gin"
)
func main() {
r := gin.Default()
r.LoadHTMLFiles("test.tmpl")
r.GET("/", func(c *gin.Context) {
c.Redirect(http.StatusPermanentRedirect,"/html")
})
r.GET("/html", func(c *gin.Context) {
data := struct {
Test string `json:"test"`
}{}
if err := c.ShouldBindJSON(&data); err != nil {
c.String(http.StatusInternalServerError, "body type is not JSON!")
return
}
fmt.Println(data)
c.HTML(http.StatusOK, "test.tmpl", gin.H{
"test": data.Test,
})
})
r.Run()
}
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
this is my code:
c.HTML(http.StatusOK, "updateRecord.html", gin.H{
"patientId": record.PatientId,
"patientName": record.PatientName,
"doctorId": record.DoctorId,
"doctorName": record.DoctorName,
})
c.Redirect(http.StatusFound, "/admin/update")
I want redirect web page to ''/admin/update'',and sent some data to ''/admin/update'', ''/admin/update'' have a html file:updateRecord.html, but this way is wrong.Actually,the page have not redirect. Can you help me?
The text was updated successfully, but these errors were encountered: