Strangest thing I ever seen Java/Javascript

user9485152 Source

I have a very strange problem

My controller reads a String[] paramDescriptions

It reads well unless the sent in the ajax has size 1. If it has size 1 I'm not getting any value.

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">

Backend

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

Answers

comments powered by Disqus