2012-06-06 35 views

回答

1

核查请求返回的状态,以确定是否有错误或只是不喜欢它

if(jqXHR === 0){ 
    //do something with error 
} else { 
    //success 
} 

编辑: 尝试此

“A的代码块如果发生错误运行”

$.ajaxSetup({ 
    error: function(res){ 
    $('body').prepend(res.responseText) 
    } 
}); 

对于一种方法

def new 
    @item = Item.new 
    rescue 
    render 'shared/exception', :layout => 'overlay' 
end 

对于整个应用

class ApplicationController 
    around_filter :xhr_exceptions 
    # ... 
    private 
    def xhr_exceptions 
    yield 
    rescue 
     render('shared/exception', :layout => 'overlay', :status => 500) if request.xhr? 
    end 
end 

http://codequietly.com/blog/2010/08/rails-ajax-and-exceptions-bring-it-on如果其死尝试缓存

+0

仍然无法以任何方式捕获异常消息。 – Paul