-
-
Save low/4632695 to your computer and use it in GitHub Desktop.
(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); |
Also, make sure your Redirection Method in the Output and Debugging settings is set to "Redirect", not "Refresh".
First result in google. Thank you Low! 👍
Is it possible to get the encoded query so we can change the URL via pushstate?
"Is it possible to get the encoded query so we can change the URL via pushstate?"
+1
What should the search results tag look like within the search/ajax-results template? eg:
{exp:low_search:results query="{last_segment}" channel="{segment_1}" orderby="title" sort="asc" }
Hi Low, this is great thank you. Any pointers to integrate pagination?
@low Does this still work in the EE4 version?
@low I'd also be interested to know if this works in the EE4? @mindpixel-labs did you get it to work?
This approach still works today, but you might want to tweak the jQuery syntax (or use some other JS lib).
Use
secure="no"
in the Form tag to prevent "not authorized to perform this action" error message.