user3448806 user3448806 - 1 year ago 77
jQuery Question

Detect server down when submit remote: true in Rails

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 %>


<%= link_to @item, remote: true %>

Answer Source

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

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

You can write whatever you want in the error block.


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download