简体   繁体   English

php值每10秒刷新一次,但我希望它随页面立即加载

[英]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.

相关问题 如何显示每10秒更改一次的横幅并尊重页面刷新的时间? - How I can display a banner that changes every 10 seconds and respect the period while the page refreshes? 我们的404页每10次刷新仅加载一次〜 - Our 404 page loads only once every 10 refreshes~ 当html页面加载/刷新时,将触发php文档。 我不要那个 - When html page loads/refreshes it triggers php document. I don't want that Javascript递归倒数10到0 - Javascript recursive Countdown 10s to 0 在MySQL数据库中更新页面时,如何立即(或尽快)更新页面上的值? (不刷新) - How do I update a value on a page instantly (or ASAP) when it's updated in MySQL database? (without refresh) PHP提交刷新页面,并以提交的ID作为参数 - PHP submit refreshes the page and takes the submit's id as a parameter 我希望每个选项在HTML中用php接受两个或多个值 - I want every option accept two or more value with php in HTML 我希望php页面首先加载其他信息,然后再执行操作 - I want the php page to load first with other information & then do an operation 每次加载页面时都会触发PHP邮件功能 - PHP mail function gets triggered every time i load the page 如果我在数据库字段中的值为10,那么我想在php中显示10个图像 - if i have a value in database field as 10 then i want to show 10 images in php
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM