A
A
Andrey Demidenko2015-04-10 14:54:40
Ruby on Rails
Andrey Demidenko, 2015-04-10 14:54:40

How to repeatedly call a function from application.js?

Good afternoon.
I do the example #240 Search, Sort, Paginate with AJAX - RailsCasts
In order to implement live seach, the following is done there.

#application.js
$(function() {
  $("#contracts_search input").keyup(function() {
    $.get($("#contracts_search").attr("action"), $("#contracts_search").serialize(), null, "script");
    return false;
  });
});

But this function works only the first time when loading. How to implement so that it always works?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mikhail Osher, 2015-04-10
@Dem1

$(document).on('keyup', '#contracts_search', function() {
  // event handler
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question