How can I elegantly handle devise's 401 status in AJAX?

后端 未结 7 1980
庸人自扰
庸人自扰 2020-12-23 18:53

With devise one uses before_filter :authenticate_user! to restrict access to authenticated users only.

When an unauthenticated

7条回答
  •  青春惊慌失措
    2020-12-23 19:58

    $(document).ajaxError(function (e, xhr, settings) {
            if (xhr.status == 401) {
               $('.selector').html(xhr.responseText);
            }
        });
    

提交回复
热议问题