Skip to content

Instantly share code, notes, and snippets.

@umkasanki
Forked from low/low-search-ajax.js
Created April 12, 2016 15:21
Show Gist options
  • Save umkasanki/556b372126c1f106e030cda5cf00c8b7 to your computer and use it in GitHub Desktop.
Save umkasanki/556b372126c1f106e030cda5cf00c8b7 to your computer and use it in GitHub Desktop.
Using Low Search for ExpressionEngine with Ajax. Change any of the three variables on top to suit your needs. Tested with jQuery 1.9.0.
(function($){
$(function(){
var $form = $('#search'), // Search form
$target = $('#results'), // Results container
rp = 'search/ajax-results'; // Template for results only
// Function to execute on success
var success = function(data, status, xhr) {
$target.html(data);
};
// Hijack the form on submit
$form.submit(function(){
// Tell target we're loading
$target.html('<p>Loading...</p>');
// Add custom result page to data
var data = $form.serialize()
+ '&result_page=' + rp;
// Perform the ajax call
$.ajax({
type: 'POST',
url: $form.attr('action'),
data: data,
success: success,
dataType: 'html'
});
// Don't submit the form afterwards
return false;
});
});
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment