PHP生成xml字符串 用ajax接收的问题
test.php
<?php
SESSION_START();
header("Content-Type: application/xml; charset=gb2312");
include ("cart.php");
echo "<?xml version=\"1.0\" encoding=\"gb2312\"?>";
echo "<root><result>1</result><count>2</count></root>";
?>
-----在前台test.html用ajax接收
代码如下:
function send() {
XmlHttp=createHttp();//创建xmlhttprequest对象
XmlHttp.open("GET", "add-cart.php?id=1&name=apple&price=2.4", true);
XmlHttp.onreadystatechange = doHttpReadyStateChange;//状态改变时触发的函数 见下面
//XmlHttp.setRequestHeader("bstrHeader", "bstrValue");
XmlHttp.send(null);
}
------
function doHttpReadyStateChange() {
if (XmlHttp.readyState == 2)
{
document.getElementById("carttext").innerHTML="is loading...please wait thank you";
}
else if (XmlHttp.readyState == 4) {//这里是正确的 状态是4 并且能返回200
alert(XmlHttp.statusText);
var xmldoc = XmlHttp.responseXML; //这里返回的也是[object]
alert(xmldoc.Xml);//!!!这里返回 的确是空的 !!!
。。。。。
请问 是上面的php页格式不对 还是ajax的接收方法不对???