XML Parsing with AJAX Howto

Discussion in 'JavaScript' started by orcunyucel, Aug 6, 2006.

  1. #1
    Hi guys,
    Can you give me better links than google for XML Parsing with AJAX? I am googling but can not find any good examples for it. My friend will make XML files with Delphi and than i will parse them with AJAX and publish on my website.
     
    orcunyucel, Aug 6, 2006 IP
  2. Nafai

    Nafai Peon

    Messages:
    105
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Ajax is a misnomer. It stands for "Asynchronous Javascript with XML", but it doesn't HAVE to be xml files that you do. Ajax is all about the asynchronous part, meaning that it executes WITHOUT reloading the page.

    If he's giving you the pages in XML that's great and it makes it a bit easier depending on if you know how to use xml pages, but learning about the ajax part really has nothing to do with xml and everything to do with making asynchronous javascript calls through an XMLHTTP object.... which object depends on which browser your client is using.
     
    Nafai, Aug 7, 2006 IP
  3. orcunyucel

    orcunyucel Peon

    Messages:
    391
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I bought a book for this(Professional Ajax, Wrox). Writers described it very easily. But it needs so many lines of coding:(
     
    orcunyucel, Aug 9, 2006 IP
  4. giraph

    giraph Guest

    Messages:
    484
    Likes Received:
    27
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Okay well here is basically what you need to do.
    
    <script type="text/javascript">
    function createRequestObject() {
        var ro;
        var browser = navigator.appName;
        if(browser == "Microsoft Internet Explorer"){
            ro = new ActiveXObject("Microsoft.XMLHTTP");
        }else{
            ro = new XMLHttpRequest();
        }
        return ro;
    }
    
    var http = createRequestObject();
    
    function sndReq() {
        http.open('get', 'yourfile.php?r='+Math.random());
        http.onreadystatechange = handleResponse;
        http.send(null);
    }
    
    function handleResponse() {
        if(http.readyState == 4){
            var response = http.responseXML.documentElement;
    		//PARSING
    		alert(response.getElementsByTagName("tagnamegoeshere")["index of tag name"].childNodes["Index of child"].firstChild.data);
        }
    }
    
    
    </script>
    
    Code (markup):
     
    giraph, Aug 9, 2006 IP
  5. orcunyucel

    orcunyucel Peon

    Messages:
    391
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #5
    No giraph. I can not use php on that server. However i did it;)
     
    orcunyucel, Aug 10, 2006 IP