I'm working on a user management table. It has a column of buttons of either "Validate" or "Revoke" based on if the user is already validated or not in database. e.g.
<td><button type="button" class="btn btn-primary btn-md" onclick= "Validate(this)" userID={{user.id}}>Validate</button></td>
When the user click on the button, it will redirect to the function below that call window.location.href to redirect a new route
function Validate(user) {
var id = user.getAttribute("userID")
window.location.href = ("/userManagement/validate/" + id), true
}
The problem is, window.location.href do the GET instead of POST. How do I modify it, or is there any alternative way to redirect to my another route with the POST request?
Thanks.
Here is what I tried based on the suggestion:
$('#inset_form').html('<form action="/userManagement/validate/' + id + '" name="validate" method="post" style="display:none;"><input type="text" name="api_url" value="' + Return_URL + '" /></form>');
document.forms['vote'].submit();
or
var url = "/userManagement/validate/" + id;
var form = $('<form action="' + url + '" method="post">' +
'<input type="text" name="api_url" value="' + Return_URL + '" />' +
'</form>');
$('body').append(form);
form.submit();
it does not redirect/reload the page, and I also don't think it access to the new route. Also, I tried,
var addr = "/userManagement/validate/" + id ;
var xhr = new XMLHttpRequest();
xhr.open('POST', addr, true);
xhr.send();
Same issue as above.