我见过Java / Javascript的最奇怪的事情

时间:2018-03-14 10:24:02

标签: javascript java jquery html

我有一个非常奇怪的问题

我的控制器读取String[] paramDescriptions

除非在ajax中发送的大小为1,否则读取效果很好。如果大小为1,我没有得到任何值。



var paramDescriptions = [];


var paramDescriptionInputs = $('input[name="paramDescriptions"]');
$(paramDescriptionInputs).each(function(index, val) {
  paramDescriptions.push($(val).val());
});

console.log(paramDescriptions);


 var formData = new FormData();
 formData.append("paramDescriptions", paramDescriptions);

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<h1> 2 values or more works </h1>


<input type="text" class="form-control" placeholder="Insert the description for EXPECTED_RATE_VALUE" name="paramDescriptions" id="paramName1">


<input type="text" class="form-control" placeholder="Insert the description for EXPECTED_RATE_VALUE" name="paramDescriptions" id="paramName2">

<h1> 1 doesn't </h1>


<input type="text" class="form-control" placeholder="Insert the description for EXPECTED_RATE_VALUE" name="paramDescriptions" id="paramName3">
&#13;
&#13;
&#13;

后端

 @RequestMapping(value = "/upload/testCase" , method = RequestMethod.POST)
public @ResponseBody String uploadTestCase(@RequestParam(value = "paramDescriptions", required = false) String[] paramDescriptions) {
    System.out.println(paramDescriptions);
}

0 个答案:

没有答案