Javascript PHP从html文件中获取一些内容,然后将这些内容传递回原始html文件
我对php很陌生, 假设我在一个目录中有一个index.html和一个cal.php index.html:Javascript PHP从html文件中获取一些内容,然后将这些内容传递回原始html文件,javascript,php,html,Javascript,Php,Html,我对php很陌生, 假设我在一个目录中有一个index.html和一个cal.php index.html: <head> <script> some java script here used to display graphs based on cal.php calculated results </script> </head> <body> <form action="cal.ph
<head>
<script>
some java script here used to display graphs based on cal.php calculated results
</script>
</head>
<body>
<form action="cal.php" method="post">
<div class="row x_title">
<div class="col-md-6">
<h3>Dashboard</h3>
</div>
<select class="form-control" id="myFileSelect">
<?php
echo '<option>Choose file</option>';
foreach (glob('Report' . '/*.csv') as $file) {
list($af, $bf) = split("/", $file, 2);
list($filenam, $extnt) = split(".", $bf, 1);
echo '<option value="' . $bf . '">' . $filenam . '</option>';
}
?>
</select>
</div>
<input type="submit">
</form>
</body>
这里的一些java脚本用于显示基于cal.php计算结果的图形
仪表板
cal.php
<?php
$row = 1;
if (($handle = fopen("test.csv", "r")) !== FALSE) {
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
$num = count($data);
echo "<p> $num fields in line $row: <br /></p>\n";
$row++;
for ($c = 0; $c < $num; $c++) {
echo $data[$c] . "<br />\n";
}
}
fclose($handle);
}
$output
/* pass the output back to original html */
/* let's say pass this php variable $output to the javascript on original html */
?>
使用ajax,您可以做到这一点。来自index.html的ajax请求将调用cal.php。如果您得到响应,则cal.php应在ajax的成功函数中响应您想要的结果。谢谢,您能提供一些教程或链接供我检查吗?关于Ajex的东西?您也可以使用会话来完成此任务。