<!DOCTYPE html>
<html>
<head>
<title>My Second Ajax Script</title>
<link rel="stylesheet" href="script02.css">
<script src="script02.js"></script>
</head>
<body>
<div id="pictureBar"> </div>
</body>
</html>
img {
border-width: 0;
margin: 5px;
}
window.addEventListener("load",initAll,false);
var xhr = false;
function initAll() {
if (window.XMLHttpRequest) {
xhr = new XMLHttpRequest();
}
else {
if (window.ActiveXObject) {
try {
xhr = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e) {
}
}
}
if (xhr) {
xhr.addEventListener("readystatechange",showPictures,false);
xhr.open("GET", "flickrfeed.xml", true);
xhr.send(null);
}
else {
alert("Sorry, but I couldn't create an XMLHttpRequest");
}
}
function showPictures() {
var tempText = document.createElement("div");
var theText;
if (xhr.readyState == 4) {
if (xhr.status == 200) {
var allImages = xhr.responseXML.getElementsByTagName("content");
for (var i=0; i<allImages.length; i++) {
tempText.innerHTML = getPixVal(allImages[i]);
theText = tempText.getElementsByTagName("p")[1].innerHTML;
theText = theText.replace(/240/g,"75");
theText = theText.replace(/180/g,"75");
theText = theText.replace(/_m/g,"_s");
document.getElementById("pictureBar").innerHTML += theText;
}
}
else {
alert("There was a problem with the request " + xhr.status);
}
}
function getPixVal(inVal) {
return (inVal.textContent) ? inVal.textContent : inVal.text;
}
}
<entry>
<title>IMG_0042.JPG</title>
<link rel="alternate" type="text/html"
href="http://www.flickr.com/photos/dorismith/882587910/in/set-72157600976524175/"/>
<id>tag:flickr.com,2005:/photo/882587910/in/set-72157600976524175</id>
<published>2007-07-24T05:19:08Z</published>
<updated>2007-07-24T05:19:08Z</updated>
<dc:date.Taken>2007-07-22T13:40:36-08:00</dc:date.Taken>
<content type="html">
<p>
<a href="http://www.flickr.com/people/dorismith/">
Dori Smith</a> posted a photo:
</p>
<p>
<a href="http://www.flickr.com/photos/dorismith/882589162/" title="
IMG_0043.JPG"><img src="
http://farm2.static.flickr.com/1179/882589162_25b4d6bcbe_m.jpg"
width="180" height="240" alt="IMG_0043.JPG" /></a>
</p>
</content>
<author>
<name>Dori Smith</name>
<uri>http://www.flickr.com/people/dorismith/</uri>
</author>
<link rel="enclosure" type="image/jpeg"
href="http://farm2.static.flickr.com/1179/882589162_25b4d6bcbe_m.jpg" />
<category term="winery" scheme="http://www.flickr.com/photos/tags/" />
<category term="sonomacounty" scheme="http://www.flickr.com/photos/tags/" />
<category term="sculptures" scheme="http://www.flickr.com/photos/tags/" />
<category term="dorismith" scheme="http://www.flickr.com/photos/tags/" />
<category term="paradiseridge" scheme="http://www.flickr.com/photos/tags/" />
<category term="paradiseridgesculptures" scheme="http://www.flickr.com/photos/tags/" />
</entry>
flickrfeed.xml - snipet
Regular Expression Replacements
Condition True Part False Part From Page 34
This part is almost the same