Go Back   CodingForums.com > :: Client side development > JavaScript programming > Ajax and Design

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-29-2012, 04:18 AM   PM User | #1
jblevins1991
New to the CF scene

 
Join Date: Jun 2012
Posts: 6
Thanks: 1
Thanked 0 Times in 0 Posts
jblevins1991 is an unknown quantity at this point
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 .
jblevins1991 is offline   Reply With Quote
Old 08-29-2012, 10:08 AM   PM User | #2
AndrewGSW
Senior Coder

 
Join Date: Apr 2011
Location: London, England
Posts: 2,120
Thanks: 15
Thanked 354 Times in 353 Posts
AndrewGSW will become famous soon enough
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
AndrewGSW is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:39 PM.


Advertisement
Log in to turn off these ads.