If you just want to grab that parameters from the URL, you could simple parse the URL by using for example the following function:
function parseUrl(url) {
var urlParamSplit = url.split("?");
if(urlParamSplit.length !== 2) return "InvalidUrlNoParamsSet";
var paramsList = urlParamSplit[1].split("&");
if(paramsList.length < 1) return "InvalidUrlNoParamsFound";
var paramsObj = {};
paramsList.forEach(function(item){
var keyValueArray = item.split("=");
paramsObj[keyValueArray[0]] = keyValueArray[1];
});
return paramsObj;
}
This is only possible if the parameter names never change and there are always some parameters set.
Your ajax call could then look like the following example:
var params = parseUrl("http://localhost:8080/BIM//teacher/reports/section-exercise/assignment?assessmentId=4d8d208e-8f71-4255-b54a-4c87a002314d&assessmentType=HOMEWORK&classroomId=722bfadb-9774-4d59-9a47-89ac9a7a8f9a&courseContentId=fd51fe9b-62ed-48f9-a6d8-5635f24964d6");
// your ajax call could look like this:
$.ajax({
url: "/BIM/rest/report/assignment",
type: "POST",
dataType: "json",
data: {
assessmentId: params.assessmentId,
classroomId: params.classroomId
},
// ... further settings and callbacks ...
});
You can get the current URL of the website via location.href
. So you can call var params = parseUrl(location.href);
to parse the current URLs parameters.
And you don't need to add a hidden input field.