jquery ajax 参数放到 request playload 中

		$.ajax({
			type : "post",// 使用get方法访问后台
			dataType : "json",// 返回json格式的数据
			url : me.url,// 要访问的后台地址
			async : async,
            contentType : 'text/plain;charset=UTF-8',
            data  : param,
			complete : function(response) {
				result = me.processResponseData(response);
				if (async) {
					if ('returnerrorforrequest' == result)
						callback.apply({}, [false, result]);
					else
						callback.apply({}, [true, result]);

				}
			}
		});

上面的请求可以把请求输入放入到  request playload 中 重点是contentType在起作用

 

 

doRequest : function(service, params, async, callback) {
		var me = this, param, result;
        if (!params) {
            params = {};
        }
        param = JSON.stringify({
            service : service,
            data : params
        });

		$.ajax({
			type : "post",// 使用get方法访问后台
			dataType : "json",// 返回json格式的数据
			url : me.url,// 要访问的后台地址
			async : async,
            contentType : 'text/plain;charset=UTF-8',
            data  : param,
			complete : function(response) {
				result = me.processResponseData(response);
				if (async) {
					if ('returnerrorforrequest' == result)
						callback.apply({}, [false, result]);
					else
						callback.apply({}, [true, result]);

				}
			}
		});
		if (!async)
			return result;

	},

 

 

对应服务端获取代码

 


    @RequestMapping(value = "**/icf.service")
    public IcfResult service() throws IOException {
        String requestStr = CharStreams.toString(request.getReader());
        IcfRequest actionRequest = JSONObject.parseObject(requestStr, IcfRequest.class);
        if (actionRequest.getService().startsWith("/overflow")) {
            return Overflow.service( actionRequest);
        }
        return IcfCore.doRequest(actionRequest);
    }

 

你可能感兴趣的:(jquery,Ajax)