【问题标题】:jQuery .load() is not working on https:// connectionjQuery .load() 不适用于 https:// 连接
【发布时间】:2019-11-10 15:16:46
【问题描述】:

最近我使用 Cloudflare 向我的网站添加了 SSL 证书,从那时起下面的函数开始返回 0 (error) 并且从不加载 URL 的内容,我应该怎么做才能解决这个问题。

$(function () {
  EnderReact();
});

function EnderReact () {
  $("a").on("click", function () {
    event.preventDefault();

    if (!(($(this).attr('href')).replace(/\s/g, '') > 0)) {
      var TheURL = $(this).attr('href');
    }

    if (TheURL && !(TheURL.indexOf("http") > -1 || TheURL.indexOf("https") > -1 || TheURL.indexOf("//") > -1)) {
      TheURL = "https://" + TheURL + "?v=0.001";
      $("#MyDiv").load(TheURL, { name: '' },
        function (response, status, xhr) {
          EnderReact();
          if (status == "error")
            alert(xhr.status + " (" + xhr.statusText + ")");
          else
            alert(xhr.status + " (" + xhr.statusText + ")");
        });
    }
  });
}

注意:控制台错误为ERR_NAME_NOT_RESOLVED

【问题讨论】:

  • ERR_NAME_NOT_RESOLVED 表示您在 url 中使用的域无效或没有 AAAAA 记录。您用于解析 url 的代码可能已损坏。试试console.log url转换的结果。

标签: javascript jquery ajax https cloudflare


【解决方案1】:

使用此代码:

<meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests">

【讨论】:

    【解决方案2】:

    这是 cloudflare ssl 设置的普遍问题。 检查他们的 gaq:

    here

    试试这段代码,看看哪一行有错误:

    $(document).ready(function () {
        if (window.location.href.indexOf("http:") > -1){ 
           console.log("URL contains http");
        }else if(window.location.href.indexOf("https:") > -1){ 
           console.log("URL contains https");
        }else if(window.location.href.indexOf("//") > -1) {
           console.log("URL contains twitter");
        }
    });
    

    【讨论】:

    • 不,我在控制台中得到的是:POST https://TheURL net::ERR_NAME_NOT_RESOLVED
    • 您是否将您的名称服务器更改为来自 cloudflare 的给定名称服务器?
    • 是的,我已经改了
    • 查看我更新的答案 使用该代码查看它是否有效,首先编辑您的 url 参数TheURL
    猜你喜欢
    • 1970-01-01
    • 2013-04-29
    • 1970-01-01
    • 1970-01-01
    • 2011-07-07
    • 2012-12-11
    • 1970-01-01
    • 2015-11-02
    • 1970-01-01
    相关资源
    最近更新 更多