Ajax SpringMVC 提交表单数据

前端之家收集整理的这篇文章主要介绍了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; } }

原文链接:https://www.f2er.com/springmvc/162063.html

猜你在找的SpringMVC相关文章