前端AJAX传递数组给Springmvc接收处理


前端传递数组后端(Spring)来接收并处理:

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>测试页面</title>
<script type="text/javascript" src="http://www.ostools.net/js/jquery/jquery-1.7.2.js"></script>
<script type="text/javascript">
function ccc() {
	var btn = document.getElementById("btn");
	$.ajax({  
		type:'post',  
		                  url:'http://localhost:8080/event/add.do',  
		                  data: {url:["www.baidu.com","www.qq.com"]},
		                  dataType:'text',//服务器返回的数据类型 可选XML ,Json jsonp script htmltext等  
		                  success:function(msg){  
		                          },  
		                  error:function(){  
		                  alert('error');  
		                  }  
		        }) 
}

</script>
</head>
<body>
    <div>
        <button id="btn" onclick=ccc()>点击测试</button>
    </div>
</body>
</html>

  后端:

 @RequestMapping(value = "add")
    public void add( @RequestParam(value = "url[]",required = false,defaultValue = "") String[] url,
                                HttpServletResponse response)
    {
        
     System.out.println(url)
        
    }


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM