Javascript js无法使用php读取小文本文件

Javascript js无法使用php读取小文本文件,javascript,php,file-get-contents,readfile,Javascript,Php,File Get Contents,Readfile,尝试将php中的小文本文件读入js变量。但即使“tmp/data.txt”的内容=30086895,警报也不会显示任何内容 function sort_rating() {reset_colors(); read_reg; myArray = myArray.sort(function(a, b){ return b.rate - a.rate;}); fortify(); newcomers();} function newcomers() { // data = '<?php cl

尝试将php中的小文本文件读入js变量。但即使“tmp/data.txt”的内容=30086895,警报也不会显示任何内容

function sort_rating() {reset_colors(); read_reg; 
myArray = myArray.sort(function(a, b){ return b.rate - a.rate;}); fortify(); newcomers();}

function newcomers() {
// data = '<?php clearstatcache(); echo readfile("tmp/data.txt"); ?>'; alert(data);
data = '<?php clearstatcache(); echo file_get_contents("tmp/data.txt"); ?>'; alert(data);
}
函数sort_rating(){reset_colors();read_reg;
myArray=myArray.sort(函数(a,b){return b.rate-a.rate;});fortify();newcomers();}
函数新来者(){
//数据=“”;警报(数据);
数据=“”;警报(数据);
}

我怎样才能做到这一点呢?

通过实际输出
文件获取内容的返回值
也许…?你能分享你的完整代码吗?对不起,我更正了“echo”遗漏。该脚本仅在第一次使用时有效。由于新的数据被附加到“tmp/data.txt”中,我希望能在中阅读并处理这些内容。“clearstatcache();”应该有助于显示当前内容,但事实并非如此。我能做什么?Re:这个脚本只在第一次运行。PHP只运行一次。它在准备HTTP响应并将其发送回客户端时在服务器上运行。如果您希望在不重新加载整个页面的情况下进行更复杂的客户机-服务器交互,那么Javascript将能够重复查询服务器端PHP脚本。但是,也就是说,与
tmp/data.txt
不同,您可能会发现更容易使用客户端存储,如。好消息!“fetch命令简单有效,非常感谢您让我走上了正确的道路,@Rounin”