当前位置:Gxlcms > PHP教程 > responseXML没法取得结果

responseXML没法取得结果

时间:2021-07-01 10:21:17 帮助过:14人阅读

responseXML无法取得结果
代码如下:
header('Content-Type: text/xml');
header("Cache-Control: no-cache, must-revalidate");

$q = $_GET["q"];


// include_once("../public/dbManager.php");
// include_once("../public/stringConvert.php");;


$con = mysql_connect('localhost', 'root', 'root');
if (!$con) {
die('Could not connect: ' . mysql_error());
}

mysql_select_db("ajax_demo", $con);

$sql = "SELECT * FROM user WHERE id = " . $q . "";

$result = mysql_query($sql);

echo '
';
while ($row = mysql_fetch_array($result)) {
echo "" . $row['FirstName'] . "";
echo "" . $row['LastName'] . "";
echo "" . $row['Age'] . "";
echo "" . $row['Hometown'] . "";
echo "" . $row['Job'] . "";
}
echo "
";

mysql_close($con);
?>

上述代码只要引入了其他文件,注释部分
// include_once("../public/dbManager.php");
// include_once("../public/stringConvert.php");
所示。
responseXML 便无法获取结果,并且执行到xmlDoc.getElementsByTagName("firstname")[0].childNodes[0].nodeValue;
处程序便不再执行。
如果去掉include语句,程序运行正常。
上述引入的文件没有任何页面输出。
本人刚接触php ,请高手解答此为何故, 谢谢。


------解决方案--------------------
先看看XML是否正确返回的再说,调试功夫不能没有吧。
------解决方案--------------------
PHP数组与xml相互转换封装函数:xmlparse.php
PHP code

#将数组转为xml
include(dirname(__FILE__)."/xmlparse.php");
$listtags = explode(" ","name");
$arr = array(1,"name"=>"SOM","admin",100,array("name"=>"TOM","Lily"));
$contXML = dump_xml_config($arr, "xml", "utf-8");
//放入文件
//file_put_contents_safe("/path/test.xml",$contXML,"w");
echo $contXML;
#源码
#
#
#    <0>1
#    SOM
#    <1>admin
#    <2>100
#    <3>
#        TOM
#        <0>Lily
#    
#

------解决方案--------------------
header('Content-Type: text/xml');
header("Cache-Control: no-cache, must-revalidate");
将这两句注释掉。将包含文件打开。打开错误提示功能,看是否报错。

人气教程排行