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 "
echo "
echo "
echo "
echo "
}
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
#将数组转为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;
#源码
#<?xml version="1.0" encoding="utf-8"?>
#<xml>
# 10>
# <name>SOM</name>
# admin1>
# 1002>
#
# <name>TOM</name>
# Lily0>
# 3>
#</xml><br><font color="#e78608">------解决方案--------------------</font><br>header('Content-Type: text/xml');<br>header("Cache-Control: no-cache, must-revalidate");<br>将这两句注释掉。将包含文件打开。打开错误提示功能,看是否报错。 <div class="clear"></div>
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号