Git Product home page Git Product logo

ajaxsearch's Introduction

AutoComplete Example With AJAX


Installation

  • fork
  • clone
  • cd into app folder
cd AJAXSearch
  • run
rails db:create && rails db:migrate && rails db:seed
  • start server
rails server

Usage

This repository contains examples of three different ways to execute an ajax request.

  • Javascript - Refer to home.js

  • Jquery - Refer to home_ajax.js

    • To use the jquery way, comment out all the in home.js and uncomment code in home_ajax.js
    • The general gist of the code for javascript and jquery is the same. Listen for the key up event and then send a request and populate your list.
  • The Rails Way - Using remote: true

    • Unfortunately, doing it the rails way is slightly different. The rails way performs its ajax request when a button is pressed (for e.g. when you submit a form). However, our current event is not a form being submitted, it is a keyup event. For it to work, you would need to press enter after typing the name of a city. It is basically not a autocomplete event but the purpose of this is to show you how to perform an ajax request through the rails way.

    • To use it the rails way, uncomment out code in both home.js and home_ajax.js. In our generic/home.html.erb, add remote: true option to your form_tag, like this:

      <%= form_tag search_path, id: "city-search", remote: true do %>

ajaxsearch's People

Contributors

cysheng avatar hinsei avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.