Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Ajax dropdown


Go to End


751 Views

Avatar
craig-opticblaze

Community Member, 10 Posts

23 February 2017 at 7:47pm

I followed Uncle Cheese's Ajax tutorial which I have working with some links that query a different page and url.

What I want to do now is add the Ajax queries to a drop down list instead. So when a value is selected from the drop down it will go to initiate the request.

Is there a way to get this working?

if ($('.pagination').length) {
        var paginate = function (url) {
            var param = '&ajax=1',
                ajaxUrl = (url.indexOf(param) === -1) ? 
                           url + '&ajax=1' : 
                           url,
                cleanUrl = url.replace(new RegExp(param+'$'),'');

            $.ajax(ajaxUrl)
                .done(function (response) {
                    $('.main').html(response);
                    $('html, body').animate({
                        scrollTop: $('.main').offset().top
                    });
                    window.history.pushState(
                        {url: cleanUrl},
                        document.title,
                        cleanUrl
                    );
                })
                .fail (function (xhr) {
                    alert('Error: ' + xhr.responseText);
                });
        };