responseXML没法取得结果

WBOY
Release: 2016-06-13 13:26:57
Original
902 people have browsed it

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;
#源码
#<?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>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template