Milk Milk - 1 month ago 7x
HTML Question

Submit a form without query string

I'm on a page like
that has a form
<form id="formId" method="POST">

What's the best way to submit the form to
without the query string?

I'm currently trying:

var url = window.location.href;
if (url.indexOf("?") != -1){
$('#formId').attr('action', url.split("?")[0]);

but it doesn't seem to be working.

I prefer a javascript/jQuery solution as this pattern is common through the site


Instead of attempting to change the action on submit, how about just looking for forms without action attributes and setting them appropriately, for example

jQuery(function($) {
    $('form:not([action])').attr('action', location.pathname);