Lai Yu-Hsuan
Lai Yu-Hsuan

Reputation: 28071

how to set timeout in rails UJS?

The new and cool syntax allows me to write:

link_to some_path, :remote => true

to generate an AJAX request. But if I need longer timeout(e.g. 100000ms), where can I set it? I read link_to but found nothing.

Upvotes: 4

Views: 1308

Answers (1)

ambisoft
ambisoft

Reputation: 11

You can use $.rails.ajax property from jquery-ujs, to inject the timeout if it has not been passed explicitly:

$(function() {
    // ...

    $.rails.ajax = function(options) {
      if (!options.timeout) {
        options.timeout = 100000;
      }      
      return $.ajax(options);
    };

    // ...
});

Upvotes: 1

Related Questions