ajax发送json数据

通过$.ajax()向后段服务发送json数据必须设置contentType值为application/json,并且调用JSON.stringify()方法


function doAjax2(){
		
	var data = {};
		
	data["param1"] = "val1";
	data["param2"] = "val2";
		
	$.ajax({
		url:'${pageContext.request.contextPath }/rest/jsonBody',
		type:'POST',
		dataType:'json',
		contentType:'application/json;charset=UTF-8',
		data:JSON.stringify(data),
		success:function(data, status){
			console.log(data);
		}
	});
		
}

你可能感兴趣的:(JavaScript,Json,Jquery,json)