2013-05-17 158 views
0

目前,即时通讯使用下面的js行来加载我的HTML页面的网站。加载外部网站视图jQuery ajax

window.location = 'http://example.com'; 

我如何使用jQuery/AJAX加载只有http://example.com返回HTTP状态200,如果出事了类似错误500,504 ....等显示另一页。

+0

你看了文档吗? http://api.jquery.com/jQuery.ajax/ – slinky2000

回答

1

这应该让你开始。

$.ajax({ 
    url: "http://www.example.com" 
}).done(function() { 
    alert('done') 
}).error(function() { 
    alert('error') 
}); 
2

window.location重定向到指定的url,是dosn't加载你的HTML页面的URI。

根据你的问题: jQuery Ajax error handling, show custom exception messages显示如何处理ajax错误。在你的情况下,错误处理可能看起来像这样:

error: function (xhr, ajaxOptions, thrownError) { 
    window.location = 'http://example.com'; 
    }