我有这个 php 文件 graph.php
$host = $_POST['hostname'];
echo $type=$_POST['type_char'];
include('rrdtools.inc.php');
include('graphs/'.$type.'.inc.php');
我尝试使用此 ajax 代码将数据发送到此文件
var type_char='fortigate_cpu';//$('#graph').val();
var hostname='10.10.0.144';//$(this).attr('id');
//$('#device_host').val(id);
$.ajax({
type: 'POST',
url: 'SNMP/graph.php',
data: { hostname:hostname,type_char:type_char },
success: function(data) {
alert(data);
// show the response
$("#grph").attr("src", 'SNMP/graph.php');
console.log(data);
}
});
当我将数据发送到该文件时的结果是
当我在 apache 日志中打开 error.log 文件时,fortigate_cpu 作为 type_char 变量的值我有这条消息
include(): 无法打开“graphs/.inc.php”以进行包含 (include_path='.:/usr/share/php')
如您所见,即使 char_type 变量由 ajax 发送并打印在页面包含文件中,包含函数中也不包含 fortigate 的值也必须如此
include( 'graphs/fortigate_cpu.inc.php')
为什么即使从 ajax 接收到变量,包含会话中也不包含类型
正如其他用户在评论中提到的,也许您的问题是您在包含 rrdtools.inc.php 后将 type 设置为不同的值。
尝试随机化(更改名称),类型变量:
$host = $_POST['hostname'];
echo $type123456=$_POST['type_char'];
include('rrdtools.inc.php');
include('graphs/'.$type123456.'.inc.php');
这是我唯一能想到的,因为我(和其他人)都测试了您的代码。(前端和后端)。
PS:包含使用 post 参数是一种不好的做法。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句