after an ajax call my js code doesn’t load until i refresh the page

So i found a hackway to do this, However is there a better solution or a way to fix my issue? And is what i did here bad?:

I added location.reload() to the end of the btn-filter on click which will reload the page since reloading the page fixes the issue for me.

I then added the code below to the top of the script:

var window_url = window.location.href;
var url_filter_params = window_url.substr(window_url.indexOf("=") + 1)
var filter_params_array = url_filter_params.split(',');

$('button[name="filter[]"]').each(function()
{
    if ($.inArray($(this).val(), filter_params_array) >= 0){
        $(this).addClass('is-success');
    }
});

This basically gets the URL parses it to get the params, and then shows adds the is-warning class back to the button to make it appear as selected. The filters also work.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top