最近,我已经在我的网站上添加了使用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
您在click函数上使用事件默认功能,但未在该函数中传递事件参数
对此进行更改,并在每行下方发出警报!
$(“ a”)。on(“ click”,函数(事件)
使用此代码:
<meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests">
这是cloudflare ssl设置的普遍问题。检查他们的gaq:
尝试此代码,看看哪一行有错误:
$(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");
}
});