I'm using this code to connect to the server via jQuery
var jqxhr = $.post('@Url.Action("../CheckMessage")',  { 'MessageId': MessageId }, 
    function (data, s) {
        alert ('This is executed on success only - data: ' + data + 's: ' + s);
    }
)
.error(function(XMLHttpRequ开发者_C百科est, textStatus, errorThrown) { alert("error"})
If I create a new exception in the server .error method is correctly executed, but if I take the server down, then success method is executed.
How can I check if the connection to the server was lost?
Ajax recall the cached data for subsequent request if you do not sepecify cache as false in the ajax setting. Try this cache:false using $.ajax.
$.ajax({
     url:  '@Url.Action("../CheckMessage")',
     data: { 'MessageId': MessageId }, 
     cache: false,
     success: function (data, s) {
        alert ('This is executed on success only - data: ' + data + 's: ' + s);
     },
     error: function(XMLHttpRequest, textStatus, errorThrown) { 
       alert("error");
     }
});
.
                                        
                                        
                                        
                                        
                                        
                                        
                                        
                                        
 加载中,请稍侯......
      
精彩评论