There seems to be an issue with the parameter when using the API to request data from the server. The value 'occupation=01%02' works correctly when entered directly into the browser URL, but errors occur when using 'occupation=01%2C02' (,) or 'occupation=01&occupation=02'.
This problem arises specifically when requesting multiple values from checkboxes to the server.
I am wondering if this could be an encoding problem. If not, where could I have made a mistake?
I am working on an HTML5 client and receiving 10 items at a time from the server which are then paginated.
In Java:
uri = new URIBuilder()
.setScheme("http")
.setHost("openapi.work.go.kr")
.setPath("/opi/opi/opia/wantedApi.do")
.setParameter("returnType", "xml")
.setParameter("startPage", requestVo.getStartPage())
.setParameter("callTp", "L")
.setParameter("region", "30200")
.setParameter("occupation", requestVo.getOccupation())
.setParameter("keyword", requestVo.getKeyword())
.setParameter("authKey", requestVo.getKey())
.build();
In JSP: the checkbox id is occupation_chbox and I populate the value in
<input type="hidden" name="startPage" value="1">
Using JavaScript:
function jobsubmit(){
var form = document.getElementById("requestForm");
var occ = checkOcc();
$("#occupation").val(occ);
console.log($("#occupation").val());
form.submit();
}
function checkOcc(){
var chk_arr = [];
$("input[id='occupation_chbox']:checked").each(function(){
var chkBox = $(this).val();
chk_arr.push(chkBox);
});
console.log(chk_arr);
var occ="";
for(i = 0; i<chk_arr.length; i++){
occ += (i < chk_arr.length - 1) ? chk_arr[i] + "," : chk_arr[i];
}
console.log(occ);
return occ;
}