[英]php value refreshes every 10s but I want it to load instantly with page
I'm currently using the following code to push the last bitcoin price into the placeholder field of an input textbox every 10 seconds: 我目前正在使用以下代码,每10秒将最后一个比特币价格推入输入文本框的占位符字段中:
var auto_refresh = setInterval(
function()
{$.get('gox.php', function (data) {
$("#inputid").attr('placeholder', data);
});}, 10000);
gox.php outputs a value (eg 99.9999) gox.php输出一个值(例如99.9999)
The problem is when I load my page the placeholder remains blank (since I set placeholder="" in the html) and doesn't refresh to the bitcoin price until 10 seconds have passed (the 10000 you see in the code). 问题是,当我加载页面时,占位符保持空白(因为我在html中设置了placeholder =“”),并且直到经过10秒(在代码中看到的10000)才刷新到比特币价格。
I have tried: 我努力了:
function()
{$.get('gox.php', function (data) {
$("#inputid").attr('placeholder', data);
});}
But it doesn't work. 但这是行不通的。
My goal is to have the bitcoin price populate the placeholder value as soon as the page is loaded and then refresh it every 10 seconds. 我的目标是在页面加载后立即让比特币价格填充占位符值,然后每10秒刷新一次。
Thanks in advance for your help! 在此先感谢您的帮助!
var refreshBitCoin = function() {
$.get('gox.php', function (data) {
$("#inputid").attr('placeholder', data);
});
}
At the bottom of the page (or within a jquery ready block) 在页面底部(或在jquery ready块内)
refreshBitCoin();
setInterval(refreshBitCoin, 10000);
Create an external function 创建一个外部功能
function page_info(){
$.get('gox.php', function (data) {
$("#inputid").attr('placeholder', data);
});
}
$(document).ready(function(){
page_info(); // refresh
var auto_refresh = setInterval(page_info, 10000);
});
function updateBitCoin(){
$.ajax({
'url' : 'gox.php',
'type' : 'GET',
success : function(data){
setTimeout('updateBitCoin()', 10000);
$("#inputid").attr('placeholder', data);
}
})
}
$(updateBitCoin);
That will fire the function at the begining and continue it every ten seconds 这将在开始时触发该功能,并每十秒钟继续执行一次
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.