weixin_33701251 2013-05-18 20:06 采纳率: 0%
浏览 16

无法使AJAX脚本正常工作

I have a table which has a list of transactions and am trying to do update the table contents at set intervals. I am running this page on a linux red hat server. It is just the AJAX that is not working right now.

<!doctype html>
<html>

    <head>
        <script>
            function updateTrans() {
                var xmlhttp;

                if (window.XMLHttpRequest) {
                    xmlhttp = new XMLHttpRequest();
                } else {
                    xmlhttp = new ActiveXObject("Microsoft.HTTP");
                }

                xmlhttp.onreadystatechange = function () {

                    if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                        document.getElementById("transactions").innerHTML = xmlhttp.responseText;
                    }

                }

                xmlhttp.open("GET", "update_trans.txt", true);
                xmlhttp.send();
            }

            window.setInterval(updateTrans(), 4000);
        </script>
        <link href="trans_styles.css" rel="stylesheet" type="text/css">
    </head>

    <body>
         <h1 id="heading"> Chomp The Bit </h1>

        <div id="transactions">
            <table id="trans_tbl" border="0">
                <tr>
                    <th colspan="2">Latest Transactions</th>
                </tr>
                <tr>
                    <td>aaaaaaaaaaaaaaaaaaaaaaaaaaaaa</td>
                    <td>aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa</td>
                </tr>
                <tr>
                    <td>bbbbbbbbbbbbbbbbbbbbbbbbbbbbb</td>
                    <td>bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb</td>
                </tr>
                <tr>
                    <td>ccccccccccccccccccccccccccccc</td>
                    <td>cccccccccccccccccccccccccccccc</td>
                </tr>
                <tr>
                    <td>ddddddddddddddddddddddddddddd</td>
                    <td>dddddddddddddddddddddddddddddd</td>
                </tr>
                <tr>
                    <td>eeeeeeeeeeeeeeeeeeeeeeeeeeeee</td>
                    <td>eeeeeeeeeeeeeeeeeeeeeeeeeeeeeee</td>
                </tr>
                <tr>
                    <td>fffffffffffffffffffffffffffff</td>
                    <td>ffffffffffffffffffffffffffffffff</td>
                </tr>
                <tr>
                    <td>ggggggggggggggggggggggggggggg</td>
                    <td>gggggggggggggggggggggggggggggggg</td>
                </tr>
                <tr>
                    <td>hhhhhhhhhhhhhhhhhhhhhhhhhhhhh</td>
                    <td>hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh</td>
                </tr>
                <tr>
                    <td>iiiiiiiiiiiiiiiiiiiiiiiiiiiiii</td>
                    <td>iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii</td>
                </tr>
                <tr>
                    <td>jjjjjjjjjjjjjjjjjjjjjjjjjjjjjj</td>
                    <td>jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj</td>
                </tr>
            </table>
        </div>
    </body>

</html>
  • 写回答

2条回答 默认 最新

  • MAO-EYE 2013-05-18 23:14
    关注

    Make sure to have, update_trans.txt file in the same directory, and it is not empty.

            <head>
                <script>
                    function updateTrans() {
                        var xmlhttp;
    
                        if (window.XMLHttpRequest) {
                            xmlhttp = new XMLHttpRequest();
                        } else {
                            xmlhttp = new ActiveXObject("Microsoft.HTTP");
                        }
    
                        xmlhttp.onreadystatechange = function () {
    
                            if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                                document.getElementById("transactions").innerHTML = xmlhttp.responseText;
                            }
    
                        }
    
                        xmlhttp.open("GET", "update_trans.txt", true);
                        xmlhttp.send();
                    }
    
                    window.setInterval(updateTrans(), 4000);
                </script>
                <link href="trans_styles.css" rel="stylesheet" type="text/css">
            </head>
    
            <body>
                 <h1 id="heading"> Chomp The Bit </h1>
    
                <div id="transactions">
    
                 </div>
            </body>
    
        </html>
    
    评论

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?