javascript获取文件内容

时间:2014-05-04 16:43:36

标签: javascript file-get-contents

我想知道JavaScript中有一些东西可以加载给定文件的内容。例如,我有一个名为timer.php的文件,在某些条件下它打印10,我需要JavaScript来读取它并将其用作变量才能执行一个功能。

类似于:

function dothis() {

 var timer = getfilecontents(timer.php);

 if(timer == 1) {
   somefunction();
 }
}

这就是它。我该怎么办?

1 个答案:

答案 0 :(得分:0)

再试一次AJAX

dothis

<script>
function dothis(){
    $.ajax({
        type: 'get',
        cache: false,
        url: 'http://example.com/timer.php',
        beforeSend:function() {
            console.log('loading...');
        },
        success: function(response) {
            console.log(response)
        }
    });
}
</script>
相关问题