..打算尝试另一种方式..
到另一个页面的链接对我来说不是很有用.. 我已经查看了其中的大多数,但无法根据我的需要调整它们。
我不熟悉 ajax 或 jQuery。
我真的可以使用一些关于这个特定问题的详细代码示例的帮助。提前致谢..
我有这段代码叫做:JSON_generator.php
<?php
require_once 'EasyWebFetch.php';
$callback = isset($_GET['callback']) ? $_GET['callback'] : 'mymap.weatherhandler';
$station = isset($_GET['rid']) ? $_GET['rid'] : 'FWS';
$product = isset($_GET['product']) ? $_GET['product'] : 'NCR';
$nframes = isset($_GET['frames']) ? $_GET['frames'] : 10;
if (strlen($product) != 3 || strlen($station) != 3) { exit; }
// fetch directory listing
$wf = new EasyWebFetch;
if (!$wf->get("http://radar.weather.gov/ridge/RadarImg/$product/$station/")) {
print $wf->getErrorMessage();
exit;
}
$page = $wf->getContents();
// echo $page."\n\n";
$size = preg_match_all( "/href=\"({$station}[\d_]+{$product}\.gif)\"/" , $page, $match);
$files = $match[1];
$nframes = min(count($files), $nframes);
$files = array_slice($files, -$nframes);
echo $callback."\n(\n{\ndirectory:\n[\n";
for ($i=0; $i < $nframes; $i++) {
echo "\"ridge/RadarImg/$product/$station/$files[$i]\",\n";
}
echo "]\n}\n)\n;"
?>
当像这样从命令行调用时......
http://example.com/mypath/JSON_generator.php?&?callback=CallBack&product=NCR&rid=JAX&frames=5
但我真正需要的是让那些 .gif 路径/文件/名称从一个首先调用 php 的 javascript 函数中“可用”。** 它们需要作为数组中的项目进行访问。
我无法弄清楚要执行此操作的javascript函数调用..
..像这样的东西,但显然不是这个..
function Feed (whichproduct, whichsite) {
var filelist = [];
var siteimages = filelist("http://example.com/mypath/JSON_generator.php?&product=whichproduct&rid=whichsite&frames=5");
..then..
//alert (filelist [1]); .. should return something like "ridge/RadarImg/NCR/JAX/JAX_20130128_2354_NCR.gif"
}
显然,我是一个初学者,所以完整的答案对我来说比代码片段更有价值。
底线:
我需要一个 javascript 函数,它可以从 php 脚本中提取每个这些 .gif 名称,并将它们带回我可以在 html 文件的其他地方使用的 javascript“var”。
谢谢,丹尼斯
编辑..编辑删除..想通了..