Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9

Thread: Ajax with xml

  1. #1
    Fot
    Fot is offline
    Regular Coder
    Join Date
    Mar 2011
    Posts
    111
    Thanks
    88
    Thanked 0 Times in 0 Posts

    Ajax with xml

    I have a problem because I cannot use background-color in a column from table with many columns.I would like advice.Thanks. I use this code:
    Code:
    function loadh(url)
    {
    var xmlhttp;
    var txt,xx,x,i;
    if (window.XMLHttpRequest)
      {// code for IE7+, Firefox, Chrome, Opera, Safari
      xmlhttp=new XMLHttpRequest();
      }
    else
      {// code for IE6, IE5
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    xmlhttp.onreadystatechange=function()
      {
      if (xmlhttp.readyState==4 && xmlhttp.status==200)
        {
        txt="<table border='1'><tr><th>County_UA</th><th>Pop_code</th></tr>";
        x=xmlhttp.responseXML.documentElement.getElementsByTagName("Data");
        for (i=140;i<x.length;i++)
          {
          txt=txt + "<tr>";
        xx=x[i].getElementsByTagName("County_UA");
            {
            try
              {
              txt=txt + "<td>" + xx[0].firstChild.nodeValue + "</td>";
              }
            catch (er)
              {
              txt=txt + "<td>&nbsp;</td>";
              }
            }
        xx=x[i].getElementsByTagName("Pop_code");
          {
            try
              {
              txt=txt + "<td>" + xx[0].firstChild.nodeValue + "</td>";
              }
            catch (er)
              {
              txt=txt + "<td>&nbsp;</td>";
              }
            }
          txt=txt + "</tr>";
          }
        txt=txt + "</table>";
        document.getElementById('ellas').innerHTML=txt;
        }
      }
    xmlhttp.open("GET",url,true);
    xmlhttp.send();
    }

  • #2
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by Fot View Post
    I have a problem because I cannot use background-color in a column from table with many columns.I would like advice.
    why you can't use background-color?
    one way to do this is here:

    http://www.htmldog.com/guides/htmladvanced/tables/

    another way is to add a inline style to the td from that column

    maybe oftopic, border='1' could be invalid but this depend of your doctype

    best regards

  • Users who have thanked oesxyl for this post:

    Fot (04-11-2011)

  • #3
    Fot
    Fot is offline
    Regular Coder
    Join Date
    Mar 2011
    Posts
    111
    Thanks
    88
    Thanked 0 Times in 0 Posts
    Thanks , also I would like to learn in the same code to be sorted by one or two fields with or without xsl.

  • #4
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by Fot View Post
    Thanks , also I would like to learn in the same code to be sorted by one or two fields with or without xsl.
    you are welcome, you can learn both, a good idea if you want to start to learn/use xsl is to learn xpath.

    best regards

  • Users who have thanked oesxyl for this post:

    Fot (04-11-2011)

  • #5
    Fot
    Fot is offline
    Regular Coder
    Join Date
    Mar 2011
    Posts
    111
    Thanks
    88
    Thanked 0 Times in 0 Posts
    Thanks.Do you know any way to reload my page when load with ajax data from xml because with every click on drop down list I have a display with previous and the every click data .

  • #6
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by Fot View Post
    Thanks.Do you know any way to reload my page when load with ajax data from xml because with every click on drop down list I have a display with previous and the every click data .
    you can use reload:

    http://www.javascriptkit.com/jsref/location.shtml

    but i dont understand what you do and why do you need to reload the page.
    if i'm not wrong and you want to refresh some information in the page after you change the state of a drop down list you can use an event attached to the drop down list, for exmple the onchange event. But you need to write a function to refresh the information according to the changes.

    best regards

  • #7
    Fot
    Fot is offline
    Regular Coder
    Join Date
    Mar 2011
    Posts
    111
    Thanks
    88
    Thanked 0 Times in 0 Posts
    The reason is because it is not possible as I have different functions and I cannot use onchange.Do you know other way to refresh my page and references for the proper function.Thanks.
    Code:
    <option value="">Select fields:</option>
    <option onclick="loadXMLDoc('w.xml')" value="3">3</option>
    <option onclick="loadm('w.xml')" value="all">all</option>
    </select>

  • #8
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by Fot View Post
    The reason is because it is not possible as I have different functions and I cannot use onchange.Do you know other way to refresh my page and references for the proper function.Thanks.
    Code:
    <option value="">Select fields:</option>
    <option onclick="loadXMLDoc('w.xml')" value="3">3</option>
    <option onclick="loadm('w.xml')" value="all">all</option>
    </select>
    you can call this functions inside the onchange event based of selection. As far as i see both have same argument, w.xml, so maybe another alternative is to rewrite the code based on selection.

    best regards

  • Users who have thanked oesxyl for this post:

    Fot (04-11-2011)

  • #9
    Fot
    Fot is offline
    Regular Coder
    Join Date
    Mar 2011
    Posts
    111
    Thanks
    88
    Thanked 0 Times in 0 Posts
    Hello, I would like help as I have a different problem with ajax and xml.The problem is that I want to display presidents information with photos by writing the year in a textbox.I try with the code below but cannot load the xml.Thanks
    Code:
    <html>
    <head>
    <title>Lookup Form</title>
    <link href="Lookup.css" type="text/css" rel="stylesheet"/>
    <script type="text/javascript">
     function Lookup(FORM)
     {
      var year = FORM.Year.value;
      if (isNaN(year) || year.length != 4)
      {
       alert("Please enter a valid year.");
       return false;
      }
    
     
     }
    
     
    </script>
    </head>
    <body>
    
    <form id="LookupForm" onsubmit="Lookup(this); return false;">
     <h1>Lookup Form</h1>
     <p>Enter a year between 1789 and 1845 to find out who was president that year.</p>
     <div class="FormRow">
      <label for="Year">Year:</label>
      <input type="text" size="5" id="Year" name="Year"/>
      <input type="submit" value="Lookup"/>
     </div>
     <hr/>
     <div class="FormRow" id="LookupResults"></div>
    </form>
    
    </body>
    </html>


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •