前端传递数组后端(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) }
时间: 2024-10-21 14:15:56