Beautify URL – Filter values before submitting Form

Case: Say you are using pjax and your site’s search page has a form with 3 inputs (A, B and C), when user only changes value of filter C, and submit the form, your site’s URL will transform into something like:

Problem: Ugly URL

Solution: Filter values before submitting form

Predicted result:


$formSearch.submit(function(event) {
    var $form = $(this);
    var options = {}; = $form.find(":input").filter(function() {
        return $(this).val() !== '';
    $.pjax.submit(event, '#pjax-container', options);

Leave a Reply

Your email address will not be published. Required fields are marked *