Sunday, August 14, 2022
HomeWordPress Developmentphp - Search Ajax Name - Use Kind Information in Response

php – Search Ajax Name – Use Kind Information in Response


I’ve an AJAX name and I’m nervous that I’m not utilizing the serialized type information within the response correctly so I get the worth from ajax filter inputs (i.e.https://prnt.sc/gxrJE9_GocOl) however I’m doing it fallacious, proper?

The unique directions so as to add ajax filters are right here –
https://rudrastyh.com/wordpress/ajax-post-filters.html

My code under:

jQuery(operate($){
//ajax name
jQuery('#filter').submit(operate(e) {
    e.preventDefault();
    var filter = jQuery('#filter');
    jQuery.ajax({
        url: filter.attr('motion'),
        information: filter.serialize(), // type information
        cache: false,
        kind: filter.attr('methodology'),
        beforeSend: operate(xhr) {
            filter.discover('.btn-filter').textual content('Filtering...');
            console.log(filter.serialize());
        },
        success: operate(information) {
            filter.discover('.btn-filter').textual content('Apply filter');
            var iso = $scroll_container.information('isotope');
            var search_total = jQuery('#search-total');

            //take away preliminary outcomes infinite scroll and isotope for ajax name
            if (iso) {
             $scroll_container.infiniteScroll('destroy');
             $scroll_container.isotope('destroy');
                $scroll_container.take away(); //fully take away preliminary outcomes 
                search_total.empty();
            }

            //if ajax infinite scroll and isotope exist already take away so reset 
            //var inf_ajax = $ajax_container.information('infiniteScroll');
            var iso_ajax = $ajax_container.information('isotope');

            if (iso_ajax) {
                $ajax_container.infiniteScroll('destroy');
                $ajax_container.isotope('destroy');
                $ajax_container.empty();
                search_total.empty();
            }


            //create "new" isotope occasion
            $ajax_container.isotope({
                layoutMode: 'fitRows',
                itemSelector: '.scroll-post'
            }); //isotope

            var $information = $(information);
            $ajax_container.append($information);
            $ajax_container.isotope('insert', $information);

            var isoajax = $ajax_container.information('isotope');

            //for search as a enter
            var s_term = jQuery("enter[type="hidden"][name="s"]").val();
            
            //for class as a radio
            var s_cat_term = jQuery("enter[type="radio"][name="categoryfilter"]:checked").attr("id");
            //var s_cat_term = s_cat_text.substitute(/[()/]/g, '').substitute(/s+/g, '-').toLowerCase();

            //for orderby as choose dropdown
            //var s_orderby_text = jQuery("choose[name="orderby"]:chosen").textual content(); 
            var s_orderby = jQuery("choose[name="orderby"]").val();

            if(s_orderby == undefined) {
             var s_orderby = 'date';
         }

            //for order choose dropdown and put up kind as enter
            var s_order = jQuery("enter[type="radio"][name="order"]:checked").val();

            if(s_order == undefined) {
             var s_orderby = 'desc';
         }

         var s_post_type = jQuery("enter[type="hidden"][name="post_type"]").val();

            //substitute search whole with ajax search outcomes whole
            var ajax_search_total = jQuery('#ajax-search-total').html();
            if(ajax_search_total) {
                search_total.append(ajax_search_total);
            }

          if(ajax_search_total > 9) {
            if (s_post_type == 'font') {
                var inf_path="/fonts/class/" + s_cat_term + '/web page/{{#}}/?s=" + s_term + "&orderby=' + s_orderby + '&order=" + s_order;
            } else if (s_post_type == "photograph') {
                var inf_path="/pictures/class/" + s_cat_term + '/web page/{{#}}/?s=" + s_term + "&orderby=' + s_orderby + '&order=" + s_order;
            } else if (s_post_type == "video') {
                var inf_path="/movies/class/" + s_cat_term + '/web page/{{#}}/?s=" + s_term + "&orderby=' + s_orderby + '&order=" + s_order;
            } else if (s_post_type == "snipp') {
                var inf_path="/snippets/class/" + s_cat_term + '/web page/{{#}}/?s=" + s_term + "&orderby=' + s_orderby + '&order=" + s_order;
            } else if (s_post_type == "put up') {
                var inf_path="/weblog/class/" + s_cat_term + '/web page/{{#}}/?s=" + s_term + "&orderby=' + s_orderby + '&order=" + s_order;
            } else {
                var inf_path = "/web page/{{#}}/?s=" + s_term + "&orderby=' + s_orderby + '&order=" + s_order;
            }

            console.log(inf_path);

            //create "new" infinite scroll occasion
            $ajax_container.infiniteScroll({
                path: inf_path,
                append: ".scroll-post',
                button: '.btn-scroll',
                outlayer: isoajax,
                loadOnScroll: false,
                //scrollThreshold: 300,
                checkLastPage: true,
                historical past: false, //disrupts ajax name class choices so set false
                standing: '.page-load-status',
                //hideNav: '.pagination',
                debug: true
            }); //infinitescroll 

            jQuery('.btn-scroll').on('click on', operate() {
                $ajax_container.on('load.infiniteScroll', operate(occasion) {
                    $ajax_container.isotope('format');
                    jQuery('.page-load-status').detach().appendTo(jQuery('#ajax_container'));
                }); //on load operate
            }); // on click on operate 
        } //ajax search whole better than 9
        //reset ajax filter fields breaks pagination                             
        //filter[0].reset();  
        } // success
    }); //ajax name
}); //submit operate
});

//Bind click on occasion listener to the submit button
jQuery(doc).on('click on', 'button[type="submit"]', operate() {
    jQuery(this).mother and father('type').submit();
}); 

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments