当添加某些JS行时,我的MAMP本地主机WP页面会不断重新加载,所有这些都是不相关的window.location。
我曾尝试激活和停用插件,但似乎没有任何解决办法,但是,尽管我不明白这行代码与页面重新加载之间的关系,但是删除这行代码确实可以解决该问题。此外,页面已加载,但JS未加载,并且JS控制台为空。如果是JS语法错误,那么它将在JS控制台中出现。
这是导致我的页面不断重新加载的代码行。
html = html || 'Sorry, there are currently no courses of this specification at this time. We apologize for the inconvenience';
再次删除此问题即可解决。
添加此行代码是为了为html提供默认值,因为它后面是
$(this).html(html);
这在以下代码中
$(document).ready(function() {
var location, courseName, locationId, courseNameId, url, splitted, array, html, list, parsedO;
window.coursesUpdated = {
"standard-first-aid": {
"richmond": [],
"burnaby": []
},
"emergency-first-aid": {
"richmond": [],
"burnaby": []
},
"emergency-child-care": {
"richmond": [],
"burnaby": []
},
"babysitting": {
"richmond": [],
"burnaby": []
}
};
$('ul.courses-list').each(function() {
location = $(this).prev().html();
courseName = $(this).parent().parent().prev().prev().prev().html();
locationId = location.toLowerCase();
courseNameId = sanitize(courseName);
$(this).html('');
html = '';
list = this;
courses[courseNameId][locationId].forEach(function(element) {
splitted = element.split(" ");
var month = splitted[1];
var date = splitted[2].replace(',', '').replace('th', '').replace('nd', '').replace('st', '');
array = JSON.stringify(element.match(/(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) \d{1,2}/g));
if (Date.parse(`${month} ${date}, ${year}`) > new Date()) {
html += `
<li>
<a href="../registration#${courseName}&${location}&${element}" location="${locationId}" courseName="${courseNameId}" dates='${array}'>
${element}
</a>
</li>
`;
}
window.coursesUpdated[courseNameId][locationId].push({
text: element,
times: array
});
});
// this line
// html = html || `Sorry, there are currently no ${courseName} courses in ${location} We apologize for the inconvenience.`;
$(this).html(html);
});
此外,导致此问题的其他原因是WP Map插件。将API密钥保留为空白会弹出页面,提示我填写我的API密钥。但是,在为API密钥输入任何内容后,我的页面都会以类似的方式不断重新加载。