I'm on a page like http://example.com?query=value that has a form <form id="formId" method="POST">.
What's the best way to submit the form to http://example.com without the query string?
I'm currently trying:
$('#formId').submit(function(e){
e.preventDefault();
var url = window.location.href;
if (url.indexOf("?") != -1){
$('#formId').attr('action', url.split("?")[0]);
}
$('#formId').submit();
});
but it doesn't seem to be working.
I prefer a javascript/jQuery solution as this pattern is common through the site
actionattribute in the HTML? In theory, it's a required attribute on<form>elements