All Projects → iranianpep → Ajax Live Search

iranianpep / Ajax Live Search

Licence: mit
AJAX Live Search is a PHP search form that similar to Google Autocomplete feature displays the result as you type.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Ajax Live Search

Push State
Turn static web sites into dynamic web apps.
Stars: ✭ 16 (-93.28%)
Mutual labels:  ajax, jquery-plugin, jquery
Bs grid
Bootstrap Datagrid
Stars: ✭ 184 (-22.69%)
Mutual labels:  ajax, jquery-plugin, jquery
Bpage
Based on bootstrap style, static page jump can also be asynchronous page processing pagination plugin
Stars: ✭ 96 (-59.66%)
Mutual labels:  ajax, jquery-plugin, jquery
Form
jQuery Form Plugin
Stars: ✭ 5,122 (+2052.1%)
Mutual labels:  ajax, jquery-plugin, jquery
Uploader
A lightweight and very configurable jQuery plugin for file uploading using ajax(a sync); includes support for queues, progress tracking and drag and drop.
Stars: ✭ 1,042 (+337.82%)
Mutual labels:  ajax, jquery-plugin, jquery
Swiftype Search Jquery
Elastic Site Search jQuery search plugin
Stars: ✭ 74 (-68.91%)
Mutual labels:  search, jquery-plugin, jquery
Jquery Confirm
A multipurpose plugin for alert, confirm & dialog, with extended features.
Stars: ✭ 1,776 (+646.22%)
Mutual labels:  ajax, jquery-plugin, jquery
Rangeslider.js
🎚 HTML5 input range slider element polyfill
Stars: ✭ 2,153 (+804.62%)
Mutual labels:  jquery-plugin, jquery
Tui.editor
🍞📝 Markdown WYSIWYG Editor. GFM Standard + Chart & UML Extensible.
Stars: ✭ 14,016 (+5789.08%)
Mutual labels:  jquery-plugin, jquery
Jquery Gantt
🌈 Lightweight jQuery gantt plugin.
Stars: ✭ 193 (-18.91%)
Mutual labels:  jquery-plugin, jquery
Jquery Aniview
A jQuery plugin that works in harmony with animate.css in order to enable animations only when content comes into view.
Stars: ✭ 205 (-13.87%)
Mutual labels:  jquery-plugin, jquery
Bootstrap Input Spinner
A Bootstrap 4 / jQuery plugin to create input spinner elements for number input
Stars: ✭ 176 (-26.05%)
Mutual labels:  jquery-plugin, jquery
Hc Offcanvas Nav
JavaScript library for creating toggled off-canvas multi-level navigations, allowing endless nesting of submenu elements, supporting swipe gestures, keyboard interactions and ARIA attributes.
Stars: ✭ 201 (-15.55%)
Mutual labels:  jquery-plugin, jquery
Amaranjs
Nice, sleek and stylish notifications.
Stars: ✭ 214 (-10.08%)
Mutual labels:  jquery-plugin, jquery
Jquery Contextmenu
jQuery contextMenu plugin & polyfill
Stars: ✭ 2,148 (+802.52%)
Mutual labels:  jquery-plugin, jquery
Calx.js
jQuery Calx - a jQuery plugin for creating formula-based calculation form
Stars: ✭ 190 (-20.17%)
Mutual labels:  jquery-plugin, jquery
Jquery.redirect
jQuery Redirect Plugin
Stars: ✭ 182 (-23.53%)
Mutual labels:  jquery-plugin, jquery
Disableautofill.js
Disable form auto-fill and auto-complete functions.
Stars: ✭ 201 (-15.55%)
Mutual labels:  jquery-plugin, auto-complete
Magnify
A lightweight jQuery magnifying glass zoom plugin.
Stars: ✭ 218 (-8.4%)
Mutual labels:  jquery-plugin, jquery
Percircle
⭕️ CSS percentage circle built with jQuery
Stars: ✭ 217 (-8.82%)
Mutual labels:  jquery-plugin, jquery

AJAX Live Search

AJAX Live Search is a jQuery plugin / PHP search form that searches and displays the result as you type similar to Google Autocomplete feature.

Demo

Check it out in action.

Browser Support

IE Chrome Firefox Opera Safari
IE 8+ ✔ Chrome ✔ Firefox ✔ Opera ✔ Safari ✔

Thanks to BrowserStack and JetBrains for supporting this project.

Getting started with Ajax Live Search

Getting the current example in index.php to work including creating a dummy database and a table should not take longer than 7 minutes. But it will take more in case you need to integrate it in an existing project. To achieve that assuming you have this text field:

<input type="text" class='mySearch' id="ls_query" placeholder="Type to start searching ...">

  1. Copy the folders including core, css, font, img, js and templates to your project.

  2. Specify the required configurations specially database configurations in core/Config.template.php and rename the file to Config.php. This file contains all the back-end settings for the plugin that have been explained in PHP Configs table.

  3. Include js/ajaxlivesearch.min.js or js/ajaxlivesearch.js and css/ajaxlivesearch.min.css or css/ajaxlivesearch.css in your page.

  4. Change the URL for Access-Control-Allow-Origin header in core/AjaxProcessor.php to your project URL. Currently it is https://ajaxlivesearch.com.

  5. Make sure core/Handler.php and core/Config.php are included in your (PHP) page and you have these lines at the very top of the file (Check index.php):

    use AjaxLiveSearch\core\Config;
    use AjaxLiveSearch\core\Handler;
    
    if (session_id() == '') {
        session_start();
    }
    
    $handler = new Handler();
    $handler->getJavascriptAntiBot();
    
  6. Lastly, hook the plugin to the text field and pass the required options (loaded_at & token):

jQuery("#ls_query").ajaxlivesearch({ loaded_at: , token: getToken() . "'"; ?>, max_input: , }); ```

You can also post additional parameters to the server if you need. To achieve this you should add data attributes to the search input:

<input type="text" class='mySearch' id="ls_query" placeholder="Type to start searching ..." data-additionalData="hello world!">

For example, in this case you can access the data attribute in PHP like this:

// key is transformed to lowercase
$additionalData = $_POST['additionaldata'];

jQuery Options

Name Type Required Description
loaded_at Integer Yes This is used to prevent bots from searching.
token String Yes This is used to prevent CSRF attack.
url String No Default: ajax/process_livesearch.php.
cache Boolean No This refers to Ajax request caching. Default: false
form_anti_bot String No Default: ajaxlivesearch_guard
slide_speed String No Default: fast
type_delay Integer No Default: 350
max_input Integer No Default: 20
min_chars_to_search Integer No Minimum characters length to start searching. Default: 0
page_ranges Array No Default: [0, 5, 10]
page_range_default Integer No Default: 5
form_anti_bot_class String No Default: ls_anti_bot
footer_class String No Default: ls_result_footer
next_page_class String No Default: ls_next_page
previous_page_class String No Default: ls_previous_page
page_limit String No Default: page_limit
result_wrapper_class String No Default: ls_result_div
result_class String No Default: ls_result_main
container_class String No Default: ls_container
pagination_class String No Default: pagination
form_class String No Default: search
loaded_at_class String No Default: ls_page_loaded_at
token_class String No Default: ls_token
current_page_hidden_class String No Default: ls_current_page
current_page_lbl_class String No Default: ls_current_page_lbl
last_page_lbl_class String No Default: ls_last_page_lbl
total_page_lbl_class String No Default: ls_last_page_lbl
page_range_class String No Default: ls_items_per_page
navigation_class String No Default: navigation
arrow_class String No Default: arrow

Custom Event

Name
onResultClick
onResultEnter
onAjaxComplete

Example:

jQuery(".mySearch").ajaxlivesearch({
    loaded_at: <?php echo time(); ?>,
    token: <?php echo "'" . $handler->getToken() . "'"; ?>,
    max_input: <?php echo Config::getConfig('maxInputLength'); ?>,
    onResultClick: function(e, data) {
        // get the index 1 (second column) value
        var selectedOne = jQuery(data.selected).find('td').eq('1').text();

        // set the input value
        jQuery('#ls_query').val(selectedOne);

        // hide the result
        jQuery("#ls_query").trigger('ajaxlivesearch:hide_result');
    },
    onResultEnter: function(e, data) {
        // do whatever you want
        // jQuery("#ls_query").trigger('ajaxlivesearch:search', {query: 'test'});
    },
    onAjaxComplete: function(e, data) {

    }
});

Custom Trigger

Name
ajaxlivesearch:hide_result
ajaxlivesearch:search

PHP Configurations

Name Type Required Description
dataSources Array Yes Data source for each search text field. Keys are refering to the field HTML id. Currently MySQL and mongoDB (this is in beta) are supported.

MySQL data source configs:
Name Type Required Description
host String Yes MySQL database host. It usually is 'localhost'.
database String Yes MySQL database name.
username String Yes MySQL database username.
pass String Yes MySQL database username password.
table String Yes MySQL database table that the live search searches in.
searchColumns Array Yes Search columns that the live search searches in. It can be one or many. e.g. array('column_name_1', 'column_name_2')
orderBy String No Column that the result is ordered based in it.
orderDirection String No Order direction: 'ASC' or 'DESC' for 'orderBy'. Default value: ASC
filterResult Array No Columns that need to be in the result. If it is empty all the columns will be returned.
comparisonOperator String Yes Search query comparison operator. Possible values for comparison operators are: 'LIKE' and '='.
searchPattern String Yes This is used to specify how the query is searched. possible values are: `q`, `*q`, `q*`, `*q*`.
caseSensitive String Yes Search query case sensitivity
maxResult Integer No This is used to limit the maximum number of result.
displayHeader Array No This is used to display or hide the header in the result. If 'active' is set to true header is displayed. Also, it is possible to map columns to different titles.
type String Yes Type of the datasource. Currently possible values are: 'mysql' or 'mongo'.
antiBot String Yes This is used as a security technique to prevent form submissions from those bots that do not use JavaScript. In this technique, a hidden field is populated using jQuery with this value. It can have any value, but it MUST be the same as `form_anti_bot` option passed to the jQuery plugin. By default it is set to `ajaxlivesearch_guard`.
searchStartTimeOffset Integer Yes This is used for another security technique against bots. Some bots immediately submit a form once the page is finished loading. However, for human beings it takes more time to fill a field. By default this parameter is set to 3 seconds. Assigning more than 3 seconds is not recommended.
maxInputLength Integer Yes This specifies the maximum length of characters in search field.
template String Yes This specifies the template name located in templates folder

FAQ

  • What is the risk in disabling anti_bot and token?

    form_anti_bot is a nice security feature to have but it should be fine to remove it. To achieve this you need to change validateRequest() in core/AjaxProcessor.php and remove $_POST['ls_anti_bot'] as well as changing verifySessionValue($sessionParameter, $sessionValue) in core/Handler.php. In contrast, removing the token allows anyone to create a form and use your server as the data source and therefore it is not recommended. Currently, each time the page / search form is loaded a new token is generated by calling getToken() in the form page (index.php in the current example). Then the token and anti_bot are checked using verifySessionValue($sessionParameter, $sessionValue) upon searching / sending a new request to the server. If this looks an overkill to you, in getToken() return the same token for the existing session.

  • How a column can be hidden in the result?

    This can be achieved in your template. An example can be found in templates/hiddenColumn.php

License

MIT License

Buy me half of a coffee if you like!

Donate

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].