[size=16px]
前台代码如下:
[/size]
             <script type="text/javascript">
        $(function () {
            $("#send").click(function () {
                $.ajax({
                    type: "GET",
                    url: "test1.xml",
                    dataType: "xml",
                    success: function (data, textStatus) {
                        alert(data);
                        $("#resText").html(data+textStatus);                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        alert(textStatus);
                        alert(errorThrown);                    }
                });
                $("#loading").ajaxStart(function () {
                    $(this).show();
                });
                $("#loading").ajaxStop(function () {
                    $(this).hide();
                });
            })        })
    
    </script>xml文件如下:
<?xml version="1.0" encoding="utf-8"?>
<!--注释内容-->
<table border="1">
    <tbody>
        <tr>
            <td>fdjkfdfkdkkdf</td>
        </tr>
    </tbody>
</tabl
问题:我想返回xml中的数据,结果返回的是【objectDocument】这句话,不知道哪里出问题了,请高手指教。

解决方案 »

  1.   

    你用firebug 调试一下 ,你就很明白 返回的是什么东西了!
    dataType: "xml",       // 你接受的是一个xml 对象,不是字符串,所以不能这样直接 alert
      success: function (data, textStatus) {
      alert(data);      // data 是一个对象 ! 你应当 取它的属性值!
      $("#resText").html(data+textStatus);  },
      

  2.   

    <%@ Page Language="C#" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script type="text/javascript" src="../JS/jquery-1.3.2.min.js"></script><script  type="text/javascript">  $(function () {
          $("#send").click(function () {
              $.ajax({
                  type: "GET",
                  url: "XMLFile.xml",
                  dataType: "xml",
                  success: function (data, textStatus) {              $("#resText").html($(data).find('table').text());              },
                  error: function (XMLHttpRequest, textStatus, errorThrown) {
                  alert(textStatus);
                  alert(errorThrown);              }
                  });
                  $("#loading").ajaxStart(function () {
                  $(this).show();
                  });
                  $("#loading").ajaxStop(function () {
                  $(this).hide();
              });
          })  })
        </script><html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>未命名頁面</title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
        <input id="send" type="button" value="Send"/>
         <div id="loading" style="height:50px;width:400px;background-color:honeydew;display:none;"  ></div>
            <div id="resText"  style="height: 50px; width: 400px;
                background-color: #FFDDFF">
            </div>
        </div>
        </form>
    </body>
    </html>
      

  3.   


    <script  type="text/javascript">  $(function () {
          $("#send").click(function () {
              $.ajax({
                  type: "GET",
                  url: "XMLFile.xml",
                  dataType: "xml",
                  success: function (data, textStatus) {              $("#resText").html($(data).find('table').text());              },
                  error: function (XMLHttpRequest, textStatus, errorThrown) {
                  alert(textStatus);
                  alert(errorThrown);              }
                  });
                  $("#loading").ajaxStart(function () {
                  $(this).show();
                  });
                  $("#loading").ajaxStop(function () {
                  $(this).hide();
              });
          })  })
        </script>