English 中文(简体)
简讯 未执行的时间表
原标题:JavaScript setTimeout function not executing as expected

我在座 driving,试图说明为什么这一文字不再像预期的那样执行(我昨天做了大量的工作,但我做了一些小改动, up倒了......现在我可以说明问题是什么。

    <form method="POST" name="inventory_check" id="inventory_check">    
        <input type="text" name="stock_part" id="part_input">
        <input type="hidden" name="site" value="2">
        <input type="submit" value="Check Stock" id="submit">
    </form>

    <?php
        if(isset($_POST[ stock_part ])) {
            $part = strtoupper($_GET[ stock_part ]);
            $site = $_POST[ site ];
            $filename =  system/inventory/ .$part. .txt ;
            if(file_exists($filename)) {
                $handle = fopen($filename,  r );
                $content = fread($handle, filesize($filename));
                $content = trim($content,  &l0O(10U );
                $content = trim($content,  E );
                fclose($handle);
                date_default_timezone_set( UTC );
                $mod_date = (filemtime($filename));
                $current_date = time();
                $subtract_date = ($current_date - $mod_date);
                $subtract_date = ($subtract_date/3600);
                if ($subtract_date <= 12) {
                    $stock = number_format($content);
                    echo  <script>document.inventory_check.style.display="visible";</script> ;
                    echo  <div id="stock_results">There are  .$stock.   .$part.  in stock.</div> ;
                }
                else {
                    echo  File too old. ;
                }
            }
            else {
                echo  <iframe src="http://example.com/inventory_check.php?part= .$part. &site= .$site. " height="50" width="150"></iframe> ;
                echo  <script>document.inventory_check.style.display="none";</script> ;
                echo  <div align="center"><img src="http://www.aifittingsproto.com/images/load.gif"><br /><br />Searching</div> ;
                echo  <script>setTimeOut("recheck()", 2000);</script> ;
            }
        }
    ?>
    <script>
    function recheck() {
        document.inventory_check.stock_part.value="<?php echo $part ?>";
        document.inventory_check.site.value="<?php echo $site ?>";
        document.inventory_check.submit();
    }
    </script>

Basically this checks stock of a certain item on our internal servers (different domain than web server). What I m trying to accomplish is the user keys in the part number...first it checks if the ftp-ed file exists on our server..if so, it checks the time it checks if its fresher than 12hrs, and then displays it if so. If not, it opens an iframe and sends the variables to our internal server for processing, which all works as expected. My issue is, I need to be able to have it recheck if the file exists after variables are passed through the iframe. I attempted to set this up by resending the variables and submitting the form every 2 seconds. Looking at the source, all the variables are populating as expected, etc. but it is not looping through and resubmitting the form. Any suggestions why this is failing, or a better approach? Thanks in advance.

问题回答

You should try replacing setTimeout("window.reload()", 2000) with setTimeout("window.reload", 2000). My understanding is that you need to pass functions without the brackets for timeouts.





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签