views:

72

answers:

2

I trying to make the AJAX request time-out if the web server goes down. Does anyone have a good way of doing this?

+2  A: 

Depends on what framework are you using. For example jQuery.ajax support a timeout option that does this. You can also set it globally using jQuery.ajaxSetup.

Lukáš Lalinský
+5  A: 

jQerry offers a beautiful solution

            $.ajax({
                type: "GET",
                timeout: 5000,
                url: "myurl.com",

                success: function(data) {
                    alert('Data load: '+ data);
                },

                error: function(){
                     alert('Error loading data');
                }

            });
Ghommey