gpt4 book ai didi

javascript - 加载外部网站 View jQuery ajax

转载 作者:行者123 更新时间:2023-11-28 20:30:02 24 4
gpt4 key购买 nike

目前,我使用下面的 js 行在我的 HTML 页面中加载网站。

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

如何使用 jQuery/AJAX 仅在 http://example.com 时加载返回 HTTP 状态 200,如果出现错误(例如 ERROR 500、504.... 等),则显示另一个页面。

最佳答案

window.location 重定向到指定的 url,不会将 uri 加载到您的 HTML 页面中。

根据你的问题: jQuery Ajax error handling, show custom exception messages展示如何处理 ajax 错误。在您的情况下,错误处理可能如下所示:

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

关于javascript - 加载外部网站 View jQuery ajax,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16604515/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com