在使用ajax向后台传值的时候,有的时java
$.ajax({ type: "post", async: true, data: { "records": ["123","456","789"] }, url: "xxxxx", error: function(request) {}, success: function(data) {} });
可是经过测试很快就会发现java后台没法取到参数,由于jQuery须要调用jQuery.param序列化参数,jQuery.param(obj, traditional )默认状况下traditional为false,即jquery会深度序列化参数对象,以适应如PHP和Ruby on Rails框架,但servelt api没法处理,咱们能够经过设置traditional 为true阻止深度序列化,而后序列化结果以下:jquery
records: ["123", "456", "789"] => records=123&p=456&p=789ajax
随即,咱们就能够在后台经过request.getParameterValues()来获取参数的值数组了,以下:api
$.ajax({ type: "post", async: true, traditional: true, data: { "records": ["123","456","789"] }, url: "xxxxx", error: function(request) {}, success: function(data) {} });