標籤:func bug rsh cti pen deb http log interface
$.ajax({ type: ‘GET‘, url: "/list/guidance", contentType: "application/json", data: JSON.stringify({ pageSize: 10, pageIndex: 0, }), success: function (result,status,xhr) { $(".content").html(result); }, error: function(xhr,status,error) { alert(xhr,status,error); }, })
//從request中擷取request data struct,Content-Type須為application/jsonfunc GetReqJSON(r *http.Request, reqJson interface{}) (code int, msg, debugMsg string) {if strings.Index(r.Header.Get("Content-Type"), "application/json") == -1 {return CodeContentTypeNotJSON, MsgContentTypeNotJSON, "Content-Type should be application/json,Content-Type: " + r.Header.Get("Content-Type")}var body []bytevar err errorif r.Method == "GET" {query, err := url.QueryUnescape(r.URL.RawQuery) //net/url包解碼if err != nil {return CodeReadRequestBodyError, MsgReadRequestBodyError, err.Error()}body = []byte(query)} else {body, err = ioutil.ReadAll(r.Body)if err != nil {return CodeReadRequestBodyError, MsgReadRequestBodyError, err.Error()}}err = json.Unmarshal(body, &reqJson)if err != nil {return CodeRequestJsonError, MsgRequestJsonError, err.Error()}//logs.DebugPrint(reqJson)return CodeSuccess, MsgSuccess, ""}
get 傳 json 資料