1

I am trying to learn xml and ajax for a school project I am currently working on. I need to create a chat system between two users and because I am still learning I do some "experiments" to see how things work. I am trying to get information from an xml file and to print the information on but the problem is after I get the xmlDoc. , and press CTRL+SPACE, I don't see that I have any getElement option. This is the XMLFile:

<?xml version="1.0" encoding="utf-8" ?>
<Conversation>
  <Massage>
    <To>a</To>
    <From>b</From>
    <Text>a to b</Text>
    <Date>11/12/2014</Date>
  </Massage>
  <Massage>
    <To>b</To>
    <From>a</From>
    <Text>b to a</Text>
    <Date>11/12/2014</Date>
  </Massage>
</Conversation>

And this is the html file:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript">
        function LoadXMLDoc(FileName) {
            var xmlhttp;
            if (window.XMLHttpRequest())
                xmlhttp = new XMLHttpRequest();
            else
                xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
            xmlhttp.open("GET", FileName, false);
            xmlhttp.send();
            return xmlhttp.response;
        }
    </script>
</head>
<body>
    <script>
        function Function() {
            var xmlDoc = LoadXMLDoc("XMLFile.xml");
        }
    </script>
    <form id="form1" runat="server">
    <div>
        <center>
        <h1> Chat </h1>
        <div id="Box" style="position:relative;height:200px;width:400px;border-width:2px;border-style:solid;border-color:black">
            <div id="Conversation">
            </div>
            <div id="Write" style="position:absolute; bottom:0;right:0;">
                <input type="text" id="MassageText" />
                <button id="SendMassageButton" causesvalidation="False" type="submit" onclick="Function(); return false">Send</button>
            </div>
        </div>
    </center>
    </div>
    </form>
</body>
</html>

I am learning with w3school and I don't see any problems here. Maybe there is a problem with the intellisense? I had an error message about that when I was trying to create a for loop.

B.T.W sorry if I have a bad english.

Falko
  • 17,076
  • 13
  • 60
  • 105
Xshibi
  • 21
  • 1
  • 3
  • if you use jquery it would be easier by using $(input).find() – Yehia Awad Dec 12 '14 at 08:46
  • @яша: He apparently does not? – Bergi Dec 12 '14 at 08:54
  • Don't call your functions `Function`. But you're right, every XML document has a `getElementById` method – Bergi Dec 12 '14 at 08:55
  • Is it really an XML document (sent with correct mime type)? Using `responseXML` would make more sense. – Dagg Nabbit Dec 12 '14 at 09:07
  • While you're at it, you probably want to use an async request, get rid of deprecated `center`, use proper naming conventions (no initial caps) and decide whether you're using HTML or XML (doctype is HTML, but XML namespace attribute is present and self-terminating tags have slashes at the end). Also, *message*, not massage. – Dagg Nabbit Dec 12 '14 at 09:11
  • @DaggNabbit I tried responeXML and still nothing. Plus thank you for your comments, I did everything you said. – Xshibi Dec 12 '14 at 10:22

0 Answers0