zoukankan      html  css  js  c++  java
  • get 传 json 数据

            $.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/json
    func 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 []byte
    	var err error
    	if 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, ""
    }
    

      

  • 相关阅读:
    【POJ 3669】Meteor Shower
    【BZOJ 1003】[ZJOI2006]物流运输trans
    【POJ 3662】Telephone Lines
    【UVa 1593】Alignment of Code
    【POJ 3661】Running
    [HNOI2015]开店 简要题解
    trie上构建后缀数组
    [CQOI2017]老C的方块
    [JSOI2018]潜入行动 (树形背包)
    李超线段树 总结
  • 原文地址:https://www.cnblogs.com/cdyboke/p/7375311.html
Copyright © 2011-2022 走看看