Hello I am trying to run this code but every time I open my webpage it doesn't load and I don't get the text I echo with php in the file "money.php". But if I open the console in my browser and run the code it does load. Does anyone know how I could fix this?
你好,我正在尝试运行这段代码,但是每次我打开我的网页时,它都没有加载,我也没有在“money.php”文件中得到php的文本。但是如果我在浏览器中打开控制台并运行它所加载的代码。有人知道我怎么解决这个问题吗?
<script type="text/javascript">
$('[data-update]').each(function() {
var self = $(this);
var target = self.data('update');
var refreshId = setInterval(function() { self.load(target); }, self.data('refresh-interval'));
});
</script>
<div data-update="money.php" data-refresh-interval="500">
3 个解决方案
#1
2
Use This
使用这个
<script type="text/javascript">
$(function() {
$('[data-update]').each(function () {
var self = $(this);
var target = self.data('update');
var refreshId = setInterval(function () {
self.load(target);
}, self.data('refresh-interval'));
});
});
</script>
OR This
或者这个
<script type="text/javascript">
$(document).ready(function() {
$('[data-update]').each(function () {
var self = $(this);
var target = self.data('update');
var refreshId = setInterval(function () {
self.load(target);
}, self.data('refresh-interval'));
});
});
</script>
#2
1
Wrap your code in $(function(){ ... });
so it runs after the DOM is ready:
将代码封装在$(function(){…});所以它在DOM就绪后运行:
<script type="text/javascript">
$(function(){
$('[data-update]').each(function() {
var self = $(this);
var target = self.data('update');
var refreshId = setInterval(function() { self.load(target); }, self.data('refresh-interval'));
});
});
</script>
More info: http://api.jquery.com/ready/
更多信息:http://api.jquery.com/ready/。
#3
1
Run the javascript/JQuery after
运行javascript / JQuery之后
<div data-update="money.php" data-refresh-interval="500">
#1
2
Use This
使用这个
<script type="text/javascript">
$(function() {
$('[data-update]').each(function () {
var self = $(this);
var target = self.data('update');
var refreshId = setInterval(function () {
self.load(target);
}, self.data('refresh-interval'));
});
});
</script>
OR This
或者这个
<script type="text/javascript">
$(document).ready(function() {
$('[data-update]').each(function () {
var self = $(this);
var target = self.data('update');
var refreshId = setInterval(function () {
self.load(target);
}, self.data('refresh-interval'));
});
});
</script>
#2
1
Wrap your code in $(function(){ ... });
so it runs after the DOM is ready:
将代码封装在$(function(){…});所以它在DOM就绪后运行:
<script type="text/javascript">
$(function(){
$('[data-update]').each(function() {
var self = $(this);
var target = self.data('update');
var refreshId = setInterval(function() { self.load(target); }, self.data('refresh-interval'));
});
});
</script>
More info: http://api.jquery.com/ready/
更多信息:http://api.jquery.com/ready/。
#3
1
Run the javascript/JQuery after
运行javascript / JQuery之后
<div data-update="money.php" data-refresh-interval="500">