ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Using JS to .load in search results?

August 05, 2011 4:32pm

Subscribe [2]
  • #1 / Aug 05, 2011 4:32pm

    icd2k3

    51 posts

    Hey all, using a simple form to return a page of results like site.com/portfolio/search/aonfr89nnasm

    {exp:search:simple_form channel="portfolio" result_page="portfolio/search" form_id="search_form"}
        <input type="submit" value="" class="submit" />
        <input type="text" name="keywords" id="keywords" value="" size="18" maxlength="30" />
    {/exp:search:simple_form}

    Easy peasy… however, what I want to do is be able to call a javascript function to load those results into the current page instead of loading a new page.

    I have this JS function set up:

    $('#search_form').submit(function() {
          console.log〈"submit"〉;
          return false;
    });

    So my question is, how do I get that random search string from the form and use it to load results within JS? any ideas?

  • #2 / Aug 05, 2011 5:00pm

    icd2k3

    51 posts

    A better question may be where to get the random string EE generates when it searches for something: site.com/portfolio/search/b3255090209755d3adc5808c9b732637 if I know how to get that value I can .load the results into the content div on my page so the user wont have to load an entirely new page just for the search results.

  • #3 / Aug 06, 2011 12:17pm

    the3mus1can

    426 posts

    Try something along these lines:

    jQuery('#search_form').submit(function() {
    
            var form = jQuery(this);
    
            jQuery.post(form.attr('action'), form.serialize(), function(html) {
                //do something with the search results HTML
                console.log〈html〉;
            });
    
          return false;
    });

    You do not need to worry about generating or figuring out the random string. Just let EE search do its thing.

  • #4 / Aug 08, 2011 12:14pm

    icd2k3

    51 posts

    Works perfectly, thanks so much!

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases