前台ajax给后台传递数据,并执行回调函数(success/error)

function addDiv() {
		$.ajax({
			url : "/showVideoDiv",
			traditional : true,
			type : "post",
			dataType : "json",
			data : {
				"id" : "ids"
			},
			success : function(data) {
                            if(data.state=="1"){
                                alert("成功");
                            }
 }

以上为前台jsp的function方法

以下为后台controller方法

@RequestMapping(value="/showVideoDiv",method = RequestMethod.POST)
	@ResponseBody
	public Map<String,String> showVideoDiv(String id){
		System.out.println(id);//输出字符串:ids
		Map<String,String> map = new HashMap<String,String>();       
		map.put("state", "1");//传回前台的数据
		return map;
		
	}

猜你喜欢

转载自blog.csdn.net/xiaoshuo566/article/details/80541892