From a68cfc5cd1a072b47b057693b820b89f711d44c1 Mon Sep 17 00:00:00 2001 From: uliian Date: Tue, 30 Sep 2025 09:54:32 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=EF=BC=9A=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0/=E4=BF=AE=E6=94=B9=E8=B7=AF=E7=94=B1?= =?UTF-8?q?=E7=9A=84ajax=E8=AF=B7=E6=B1=82=E8=BF=9B=E8=A1=8C=E4=BC=98?= =?UTF-8?q?=E5=8C=96=EF=BC=8C=E6=8C=87=E5=AE=9Acontent-type=E4=B8=BAapplic?= =?UTF-8?q?ation=20bugfix=EF=BC=9AAddRouter=E9=83=A8=E5=88=86body=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E6=94=B9=E7=94=A8c.Ctx.Request.Body=EF=BC=8C=E5=8E=9F?= =?UTF-8?q?=E5=85=88=E7=9A=84c.Ctx.Input=E7=9B=B8=E5=85=B3=E6=96=B9?= =?UTF-8?q?=E6=B3=95=E5=8F=96=E4=B8=8D=E5=88=B0body=EF=BC=8C=E9=80=A0?= =?UTF-8?q?=E6=88=90=E4=B8=9A=E5=8A=A1=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controllers/WebAlertRouter.go | 16 ++++++++++++---- views/alertrouter_add.html | 2 +- views/alertrouter_edit.html | 1 + 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/controllers/WebAlertRouter.go b/controllers/WebAlertRouter.go index 8f7ae551..a69ed8ef 100644 --- a/controllers/WebAlertRouter.go +++ b/controllers/WebAlertRouter.go @@ -3,8 +3,10 @@ package controllers import ( "PrometheusAlert/models" "encoding/json" - "github.com/astaxie/beego/logs" + "io" "strconv" + + "github.com/astaxie/beego/logs" ) // router @@ -68,9 +70,15 @@ func (c *MainController) AddRouter() { return } WebAlertRouterJson := AlertRouterJson{} - logsign := "[" + LogsSign() + "]" - logs.Info(logsign, string(c.Ctx.Input.RequestBody)) - json.Unmarshal(c.Ctx.Input.RequestBody, &WebAlertRouterJson) + + body, _ := io.ReadAll(c.Ctx.Request.Body) + logsign := "[" + LogsSign() + ",]" + logs.Info(logsign, string(body)) + err := json.Unmarshal(body, &WebAlertRouterJson) + if err != nil { + logs.Error(err) + return + } rules, err := json.Marshal(WebAlertRouterJson.Rules) if WebAlertRouterJson.RouterId == "" { tpl_id_int, _ := strconv.Atoi(WebAlertRouterJson.RouterTplId) diff --git a/views/alertrouter_add.html b/views/alertrouter_add.html index b43a2fed..ef586908 100644 --- a/views/alertrouter_add.html +++ b/views/alertrouter_add.html @@ -314,7 +314,6 @@

} function savetpl(){ - var uname=document.getElementById("rules"); if (uname.value.length==0){ alert('路由规则不能为空'); @@ -351,6 +350,7 @@

var json_data = JSON.stringify(alert_router_json_str); $.ajax({ + contentType: 'application/json', type: "POST", dataType: "json", url: '{{ urlfor "MainController.AddRouter"}}', diff --git a/views/alertrouter_edit.html b/views/alertrouter_edit.html index 8305ef40..a519a16b 100644 --- a/views/alertrouter_edit.html +++ b/views/alertrouter_edit.html @@ -346,6 +346,7 @@

var json_data = JSON.stringify(alert_router_json_str); $.ajax({ + contentType: "application/json", type: "POST", dataType: "json", url: '{{ urlfor "MainController.AddRouter"}}',