So currently, when my webapp makes a get request, the uri looks something like this:
users?usderId=123
What I want is
users/123
How do I do this?
Googling how to make get request in javascript gives me the former URI when I want the latter.
The reason I want the latter format is because my requestMapping in Spring looks like
@RequestMapping(value = "/users/{userId}", method = RequestMethod.GET)
Edit:
So I have tried the method in the reply and it seems like my javascript function was never being called.
<form id="idForm" class="form-inline" role="form" action="/users">
<div class="form-group">
<div class="input-group inline-input-group">
<div class="input-group-btn">
<button type="button" class="btn btn-default dropdown-toggle fixedWidth225" data-toggle="dropdown">User Id<span class="caret"></span></button>
<ul class="dropdown-menu">
<li><a href="#">aaa ID</a></li>
<li><a href="#">bbb ID</a></li>
<li><a href="#">ccc ID</a></li>
<li><a href="#">ddd ID</a></li>
</ul>
</div>
<label class="sr-only" for="EntityId">Entity Id</label>
<input type="text" class="form-control fixedWidth225" name="userId">
</div>
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
<div id="displayDiv">
</div>
This is my form and this is js:
$(document).ready(function() {
document.getElementbyID("idForm").submit(function(event) {
event.preventDefault();
var url = document.getElementbyID("idForm").attr( "action") + "/" + document.getElementbyID("userId").val();
httpGet(url);
});
});
*/
function httpGet(restURL)
{
var xmlHttp = null;
// Assuming its a text field
xmlHttp = new XMLHttpRequest();
xmlHttp.open( "GET", restURL, false );
xmlHttp.send( null );
return xmlHttp.responseText;
}
Why is my javascript function for idForm submit not being called?
---------------------------The part just above this line is figured ----------------------
Edit:
The bottom line of my question:
HTML form with submit button can make a get request with "action" specified for form and "name" specified for the input text. I just want to be able to format the URI this get request generates from users?userID=123 to users/123.
There must be a way to simply change the format of the URI, mustn't it?