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 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jun 2012
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Learning AJAX but not getting very far...

    I have a blog i am creating from scratch. I have the html page i want to publish the blog to, the javascript file that is going to be publishing the blog, and the xml file that contains the blog posts. I have looked at all of the information on the w3schools website and i cannot find what is wrong with the script. The script has a function named Blog() in it that i want activated by a button. Here is my code that i have.

    Here is the html code i have.

    [CODE]
    <div id="blog">
    <script type="text/javascript" scr="blog.js"></script>
    <button type="button" onclick="Blog()">click me</button>
    </div>
    [CODE]

    Here is the code from blog.js
    [CODE]
    function Blog()
    {
    var XHR;
    if(window.XMLHttpRequest)
    {
    XHR = new XMLHttpRequest();
    }
    else
    {
    XHR = new ActiveXObject("Microsoft.XMLHTTP");
    }

    XHR.onReadyStateChange = function()
    {
    if(XHR.readyState == 4 && XHR.status == 200)
    {
    var xmldom = XHR.responseXML;
    var output = "";
    var items = xmldom.getElementsByTagName("item");

    for(var i = 0;i < items.length;i++)
    {
    output = xmldom;
    }

    document.getElementById("blog").innerHTML = output;
    }
    }

    XHR.open("GET", "blog.xml", true);

    XHR.send();
    }
    [CODE]

    Here is the code from the blog.xml file.
    [CODE]
    <?xml version="1.0" encoding="UTF-8"?>

    <rss version="2.0">

    <channel>
    <item>
    <title>hello</title>

    <link>www.google.com</link>

    <description>world</description>
    </item>
    <item>
    <title>hello</title>

    <link>www.google.com</link>

    <description>world</description>
    </item>
    <item>
    <title>hello</title>

    <link>www.google.com</link>

    <description>world</description>
    </item>
    <title>
    Unified Feed
    </title>

    <category>
    Business
    </category>

    <language>
    US-en
    </language>

    <ttl>
    60
    </ttl>
    </channel>

    </rss>
    [CODE]

    Would love some help with this .

  • #2
    Senior Coder
    Join Date
    Apr 2011
    Location
    London, England
    Posts
    2,120
    Thanks
    15
    Thanked 354 Times in 353 Posts
    Code:
    <script type="text/javascript" src="blog.js"></script>
    Code:
    .onreadystatechange =
    "I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
    Validate your HTML and CSS


  •  

    Posting Permissions

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