javascript - phph 在使用 ssl 时不会“实时更新”
问题描述
我正在创建一个 php 网站,它使用 javascript 每 5 秒从数据库中获取值。
当我在没有 ssl 连接的情况下访问网站时,一切都运行良好,但是只要我在 url 之前键入 https://,页面就会加载,但每 5 秒更新一次的部分会一直停留在加载图像上。
这就是我接收更新的方式
索引.php
<div id="stats">
<center><img src="/images/loading.gif" alt="Loading stats" title="Loading stats" /></center>
</div>
stats.js
//stats
function loadStats(){
$.ajax({
url: 'includes/stats.php',
success: function(data) {
$("#stats").html(data);
setTimeout("loadStats()", 5000);
}
});
}
$(function(){
loadStats();
});
包括/stats.php
Here I receive the databse info and echo the html
提前致谢!
编辑:
I am using //domain/file.js now for all js/css/images but it still only
works without the ssl connection
解决方案
看起来 JQuery 没有正确加载。
莱斯利·彼得斯指出:
控制台输出如下: Uncaught ReferenceError: $ is not defined at stats.js:11
第 11 行是:
$(function(){
loadStats();
});
进行ajax回调的父页面可能没有引用jQuery,此外,请确保通过HTTPS://加载jQuery。
如果这不起作用,您可能需要考虑直接运行:
function loadStats(){
$.ajax({
url: 'includes/stats.php',
success: function(data) {
$("#stats").html(data);
setTimeout("loadStats()", 5000);
}
});
}
loadStats();
推荐阅读
- kdb - 在 KDB 中,我们可以对 .z.ph 和 .z.pp 使用延迟响应吗?
- node.js - 减少 Javascript 中的调用堆栈大小
- android - 在数据片段之间传递数据
- datadog - 如何更正 Datadog 仪表板中的查询语句(字符串插值)?
- java - View Expand Animation 通过在嵌套布局中使用“animateLayoutChanges”影响其他视图
- graphql - 如何设计具有大多数相同字段的多个对象类型
- django - Django 多重注释减慢查询速度
- android - 有没有办法让 React Native 即使在应用程序卸载时也能保留数据?
- java - 如何通过 REST API 将数据从 Angular 8 发送到 Spring Boot
- javascript - 什么是“文件是 CommonJS 模块;它可能会被转换为 ES6 模块”警告意味着什么?如何解决?