Ajax SpringMVC 提交表单数据

Ajax 的写法

function saveSplash() {
		var titleVal = $("#title").val();
		var subTitleVal = $("#subTitle").val();
		if (titleVal == null || "" == titleVal) {
			alert("标题不能为空");
			return;
		}

		if (subTitleVal == null || "" == subTitleVal) {
			alert("子标题不能为空");
			return;
		}
		var img = imgurl.substring(imgurl.lastIndexOf("/")+1,imgurl.length);
		var data={"title":titleVal,"subTitle":subTitleVal,"type":4,"imageUrl":img};
		$.ajax({
			type : 'POST',url : '${pageContext.request.contextpath}/platform/article/ads',contentType: "application/json; charset=utf-8",data : JSON.stringify(data),dataType : 'json',error : function(data) {
				alert("请求失败,网络异常")
				console.log(data);
			},success : function(data) {
				var code = data.status;
				if (code == 200) {
					window.location.href = "index";
				} else {
					alert("提交失败");
				}
			}
		});
	}

SpringMVC的写法:

@RequestMapping(value="/ads",method = RequestMethod.POST) @ResponseBody public Object saveArticleAds(@RequestBody ArticleAds articleAds,HttpServletRequest request) { xxxxx xxxxx return StatusConfig.OK; } }

相关文章

SpringMVC1.MVC架构MVC是模型(Model)、视图(View)、控制...
SpringMVC学习笔记1.SpringMVC应用1.1SpringMVC简介​Spring...
11.1数据回显基本用法数据回显就是当用户数据提交失败时,自...
一、SpringMVC简介1、SpringMVC中重要组件DispatcherServlet...
1.它们主要负责的模块Spring主要应用于业务逻辑层。SpringMV...
3.注解开发Springmvc1.使用注解开发要注意开启注解支持,2.注...