【发布时间】:2011-11-19 22:24:52
【问题描述】:
好的,我要做的是制作一个图像的 javascript 循环,但首先我必须获取图像列表。在 javascript 中没有办法直接获取这个文本文件...http://www.ssd.noaa.gov/goes/east/tatl/txtfiles/ft_names.txt 但它可以在 php 中轻松完成,我目前正在使用 php 获取 txt 文件,但 javascript 无法读取变量。我怎样才能让 javascript 能够读取这个变量。这是我所拥有的......
<?php
$file = "http://www.ssd.noaa.gov/goes/east/tatl/txtfiles/ft_names.txt"; //Path to your *.txt file
$contents = file($file);
$string = implode($contents);
echo $string;
?>
<script type="text/javascript">
function prnt() {
var whatever = "<?= $string ?>";
alert(whatever);
}
</script>
【问题讨论】:
-
你现在得到什么输出?我假设你在某处调用 prnt()?
-
您是否启用了短标签?
-
正文的内容是什么?有没有换行之类的?
-
@Doug 什么都没有,没有警告框,但是如果我在 php 中创建一个常规变量,例如。 $string = "Ok" 并且不要添加任何东西,它工作正常。
-
你确定你的 $string 不是空的并且问题没有出现在 PHP 阶段吗?
标签: php javascript string