0

Can I detect when client couldn't send request to server ? (server down or broken internet link or something ...)

Exp. when I submit form or click link with remote: true, if request couldn't come to server, I could show a message to user.

<%= form_for @item, remote: true do %>
    ....
<% end %>

 or

<%= link_to @item, remote: true %>
user3448806
  • 897
  • 10
  • 22

1 Answers1

0

You can write AJAX callbacks for remote: true requests like below.

<script>
  $(document).ready(function(){
    $('#item').on('ajax:success', function(e, data, status, xhr) {
      //Success action
    }).on('ajax:error',function(e, xhr, status, error){
      //Failure action
    });
  });
</script>

You can write whatever you want in the error block.

Ref

Community
  • 1
  • 1
Jayaprakash
  • 1,407
  • 1
  • 9
  • 19